KycInfo kycInfo; if(kycUri != null) { kycInfo = new KycInfo(investorId, false, 0, false, kycUri.toASCIIString()); } else { kycInfo = new KycInfo(investorId, false, 0, false, null); LOG.debug("Saved kycInfo in db: investorId: {}, kycUuid: {}, isKycComplete: {}", kycInfo.getInvestorId(), kycInfo.getKycUuid(), kycInfo.isKycComplete()); } catch (DataIntegrityViolationException e) { LOG.info("KycInfo for investor was already saved to database.", investorId);
private void assertKycInfo(KycInfo kycInfo, long investorId, boolean isKycStartEmailSent, int noOfRemindersSent, boolean isKycComplete, URI kycUri) { assertEquals(investorId, (long) kycInfo.getInvestorId()); assertEquals(isKycStartEmailSent, kycInfo.isStartKycEmailSent()); assertEquals(noOfRemindersSent, (int) kycInfo.getNoOfRemindersSent()); assertEquals(isKycComplete, kycInfo.isKycComplete()); assertEquals(kycUri.toASCIIString(), kycInfo.getKycUri()); }
/** * Sets the KYC process completion in the database entry for the specified investor * @param investorId The id of the investor * @param isKycComplete * @return The KYC info that was changed * @throws InvestorNotFoundException if the investor does not exist in the database */ @Transactional public KycInfo setKycComplete(long investorId, boolean isKycComplete) throws InvestorNotFoundException { Optional<KycInfo> kycInfoFromDb = kycInfoRepository.findOptionalByInvestorId(investorId); if(kycInfoFromDb.isPresent()) { KycInfo kycInfo = kycInfoFromDb.get().setKycComplete(isKycComplete); kycInfoFromDb = Optional.of(kycInfoRepository.save(kycInfo)); } return kycInfoFromDb.orElseThrow(InvestorNotFoundException::new); }
/** * Increases {@link KycInfo#noOfRemindersSent} for the specified investor by one * @param investorId The id of the investor * @return The KYC info that was changed * @throws InvestorNotFoundException if the investor does not exist in the database */ @Transactional public KycInfo increaseNumberOfRemindersSent(long investorId) throws InvestorNotFoundException { Optional<KycInfo> kycInfoFromDb = kycInfoRepository.findOptionalByInvestorId(investorId); if(kycInfoFromDb.isPresent()) { KycInfo kycInfo = kycInfoFromDb.get().setNoOfRemindersSent(kycInfoFromDb.get().getNoOfRemindersSent() + 1); kycInfoFromDb = Optional.of(kycInfoRepository.save(kycInfo)); } return kycInfoFromDb.orElseThrow(InvestorNotFoundException::new); }
if(!kycInfo.isStartKycEmailSent()) { throw new KycNotYetStartedException(); if(kycInfo.isKycComplete()) { throw new KycAlreadyCompletedException(); .body(remindKyc(investorId, new URI(kycInfo.getKycUri())));
@Test public void testFindOptionalByKycUuid() { KycInfo kycInfo = createKycInfo(1,false); KycInfo savedKycInfo = kycInfoRepository.save(kycInfo); Optional<KycInfo> oKycInfo = kycInfoRepository.findOptionalByKycUuid(savedKycInfo.getKycUuid()); assertTrue(oKycInfo.isPresent()); assertEquals(1, (long)oKycInfo.get().getInvestorId()); assertEquals(savedKycInfo.getKycUuid(), oKycInfo.get().getKycUuid()); }
@Test public void testFindOptionalByInvestorId() { KycInfo kycInfo = createKycInfo(1, false); kycInfoRepository.save(kycInfo); Optional<KycInfo> oKycInfo = kycInfoRepository.findOptionalByInvestorId(1); assertTrue(oKycInfo.isPresent()); assertEquals(1, (long)oKycInfo.get().getInvestorId()); }
@Override public String getKycLink(long investorId) throws InvestorNotFoundException { KycInfo kycInfo = kycInfoService.getKycInfoByInvestorId(investorId); return kycConfigHolder.getIdNowHost() + "/" + kycConfigHolder.getIdNowCompanyId() + "/userdata/" + kycInfo.getKycUuid(); }
private KycInfo createKycInfo(boolean isStartKycEmailSent, int noOfRemindersSent, boolean isKycComplete) { return new KycInfo(INVESTOR_ID, isStartKycEmailSent, noOfRemindersSent, isKycComplete, KYC_LINK); } }
boolean isKycComplete = kycInfo.isKycComplete(); if(!isKycComplete) { if(kycInfo.isStartKycEmailSent()) { throw new KycAlreadyStartedWithEmailException(); } else {
/** * Completes the KYC process for the specified investor * @param investorId The id of the investor for whom the KYC should be completed * @param requestContext The context of the request that called this endpoint * @return A DTO containing the investor id and a boolean for success or failure * @throws NonexistentInvestorException if the specified investor does not exist * @throws KycAlreadyCompletedException if KYC was already completed for this investor */ @RequestMapping(value = "/kyc/{investorId}/complete", method = POST, produces = APPLICATION_JSON_UTF8_VALUE) public ResponseEntity<CompleteSingleKycResponseDTO> setInvestorComplete(@PathVariable("investorId") Long investorId, @Context HttpServletRequest requestContext) throws NonexistentInvestorException, KycAlreadyCompletedException { String ipAddress = IPAddressUtil.getIPAddress(requestContext); LOG.info("/complete called from {} with investorId {}", ipAddress, investorId); try { KycInfo kycInfo = kycInfoService.getKycInfoByInvestorId(investorId); if(kycInfo.isKycComplete()) { throw new KycAlreadyCompletedException(); } else { // Complete KYC kycInfoService.setKycComplete(investorId, true); return ResponseEntity .status(HttpStatus.OK) .body(new CompleteSingleKycResponseDTO(investorId, true)); } } catch(InvestorNotFoundException e) { // KYC Process not yet started throw new NonexistentInvestorException(); } }
/** * Sets the {@link KycInfo#kycUri} for the specified investor in the database * @param investorId The id of the investor * @param kycUri The KYC URI to be assigned to the investor * @return The KYC info that was changed * @throws InvestorNotFoundException if the investor does not exist in the database */ @Transactional public KycInfo setKycUri(long investorId, String kycUri) throws InvestorNotFoundException { Optional<KycInfo> kycInfoFromDb = kycInfoRepository.findOptionalByInvestorId(investorId); if(kycInfoFromDb.isPresent()) { KycInfo kycInfo = kycInfoFromDb.get().setKycUri(kycUri); kycInfoFromDb = Optional.of(kycInfoRepository.save(kycInfo)); } return kycInfoFromDb.orElseThrow(InvestorNotFoundException::new); }
@Test public void testSetNonexistentInvestorComplete() throws Exception { KycInfo testKycInfo = createKycInfo(true, 0, false); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenThrow(new InvestorNotFoundException()); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_INVESTOR_COMPLETE) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andDo(print()) .andReturn(); verify(mockKycInfoService, never()).setKycComplete(testKycInfo.getInvestorId(), true); assertThat(result.getResponse().getErrorMessage()).isEqualTo(NONEXISTENT_INVESTOR_REASON); }
@Test public void testSetKycCompleteByUuid() throws KycInfoNotSavedException { kycInfoService.saveKycInfo(50, kycUri); Optional<KycInfo> oKycInfo = kycInfoRepository.findOptionalByInvestorId(50); assertKycInfo(oKycInfo.get(), 50, false, 0, false, kycUri); try { kycInfoService.setKycCompleteByUuid(oKycInfo.get().getKycUuid(), true); } catch(InvestorNotFoundException e) { fail(e.getMessage()); } oKycInfo = kycInfoRepository.findOptionalByInvestorId(50); assertKycInfo(oKycInfo.get(), 50, false, 0, true, kycUri); }
private KycInfo createKycInfo(long i, boolean isKycComplete) { return new KycInfo(i, false, 0, isKycComplete, "www.kycuri" + i + ".com"); }
@Test public void testSetExistingInvestorCompleteWhenKycAlreadyComplete() throws Exception { KycInfo testKycInfo = createKycInfo(true, 0,true); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenReturn(testKycInfo); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_INVESTOR_COMPLETE) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andDo(print()) .andReturn(); verify(mockKycInfoService, never()).setKycComplete(testKycInfo.getInvestorId(), true); }
@Test public void testGetKycInfoByKycUuid() throws KycInfoNotSavedException { kycInfoService.saveKycInfo(1, kycUri); UUID uuid = kycInfoRepository.findOptionalByInvestorId(1).get().getKycUuid(); try { KycInfo kycInfo = kycInfoService.getKycInfoByKycUuid(uuid); assertKycInfo(kycInfo, 1, false, 0, false, kycUri); } catch(InvestorNotFoundException e) { fail(e.getMessage()); } }
@Test public void testSave() { KycInfo kycInfo = new KycInfo(1L, false, 0, false, "www.kycuri.com"); kycInfoRepository.save(kycInfo); }
/** * Sets the KYC process completion in the database entry for the specified investor * @param uuid UUID of the investor * @param isKycComplete * @return The KYC info that was changed * @throws InvestorNotFoundException if the investor does not exist in the database */ @Transactional public KycInfo setKycCompleteByUuid(UUID uuid, boolean isKycComplete) throws InvestorNotFoundException { Optional<KycInfo> kycInfoFromDb = kycInfoRepository.findOptionalByKycUuid(uuid); if(kycInfoFromDb.isPresent()) { KycInfo kycInfo = kycInfoFromDb.get().setKycComplete(isKycComplete); kycInfoFromDb = Optional.of(kycInfoRepository.save(kycInfo)); } return kycInfoFromDb.orElseThrow(InvestorNotFoundException::new); }
@Test public void testSetExistingInvestorCompleteWhenKycIncomplete() throws Exception { KycInfo testKycInfo = createKycInfo(true, 0,false); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenReturn(testKycInfo); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_INVESTOR_COMPLETE) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(print()) .andReturn(); verify(mockKycInfoService).setKycComplete(testKycInfo.getInvestorId(), true); }