private static boolean isActionable(final LoanDescriptor loanDescriptor) { final OffsetDateTime now = DateUtil.offsetNow(); return loanDescriptor.getLoanCaptchaProtectionEndDateTime() .map(d -> d.isBefore(now)) .orElse(true); }
private static boolean isActionable(final LoanDescriptor loanDescriptor) { final OffsetDateTime now = DateUtil.offsetNow(); return loanDescriptor.getLoanCaptchaProtectionEndDateTime() .map(d -> d.isBefore(now)) .orElse(true); }
private Either<InvestmentFailure, BigDecimal> investOrDelegateOnCaptcha(final RecommendedLoan r) { final Optional<OffsetDateTime> captchaEndDateTime = r.descriptor().getLoanCaptchaProtectionEndDateTime(); final boolean isCaptchaProtected = captchaEndDateTime.isPresent() && captchaEndDateTime.get().isAfter(DateUtil.offsetNow()); final boolean confirmationSupported = this.provider != null; if (!isCaptchaProtected) { return this.investLocallyFailingOnCaptcha(r); } else if (confirmationSupported) { return this.delegateOrReject(r); } LOGGER.warn("CAPTCHA protected, no support for delegation. Not investing: {}.", r); return Either.left(InvestmentFailure.REJECTED); }
private Either<InvestmentFailure, BigDecimal> investOrDelegateOnCaptcha(final RecommendedLoan r) { final Optional<OffsetDateTime> captchaEndDateTime = r.descriptor().getLoanCaptchaProtectionEndDateTime(); final boolean isCaptchaProtected = captchaEndDateTime.isPresent() && captchaEndDateTime.get().isAfter(DateUtil.offsetNow()); final boolean confirmationSupported = this.provider != null; if (!isCaptchaProtected) { return this.investLocallyFailingOnCaptcha(r); } else if (confirmationSupported) { return this.delegateOrReject(r); } LOGGER.warn("CAPTCHA protected, no support for delegation. Not investing: {}.", r); return Either.left(InvestmentFailure.REJECTED); }
public Either<InvestmentFailure, BigDecimal> invest(final RecommendedLoan r, final boolean alreadySeenBefore) { final boolean confirmationRequired = r.isConfirmationRequired(); if (alreadySeenBefore) { LOGGER.debug("Loan seen before."); final boolean protectedByCaptcha = r.descriptor().getLoanCaptchaProtectionEndDateTime() .map(date -> DateUtil.offsetNow().isBefore(date)) .orElse(false); if (!protectedByCaptcha && !confirmationRequired) { /* * investment is no longer protected by CAPTCHA and no confirmation is required. therefore we invest. */ return this.investLocallyFailingOnCaptcha(r); } else { /* * protected by captcha or confirmation required. yet already seen from a previous investment session. * this must mean that the previous response was DELEGATED and the user did not respond in the * meantime. we therefore keep the investment as delegated. */ return Either.left(InvestmentFailure.SEEN_BEFORE); } } else if (confirmationRequired) { if (this.provider == null) { throw new IllegalStateException("Confirmation required but no confirmation provider specified."); } else { return this.delegateOrReject(r); } } else { return this.investOrDelegateOnCaptcha(r); } }
public Either<InvestmentFailure, BigDecimal> invest(final RecommendedLoan r, final boolean alreadySeenBefore) { final boolean confirmationRequired = r.isConfirmationRequired(); if (alreadySeenBefore) { LOGGER.debug("Loan seen before."); final boolean protectedByCaptcha = r.descriptor().getLoanCaptchaProtectionEndDateTime() .map(date -> DateUtil.offsetNow().isBefore(date)) .orElse(false); if (!protectedByCaptcha && !confirmationRequired) { /* * investment is no longer protected by CAPTCHA and no confirmation is required. therefore we invest. */ return this.investLocallyFailingOnCaptcha(r); } else { /* * protected by captcha or confirmation required. yet already seen from a previous investment session. * this must mean that the previous response was DELEGATED and the user did not respond in the * meantime. we therefore keep the investment as delegated. */ return Either.left(InvestmentFailure.SEEN_BEFORE); } } else if (confirmationRequired) { if (this.provider == null) { throw new IllegalStateException("Confirmation required but no confirmation provider specified."); } else { return this.delegateOrReject(r); } } else { return this.investOrDelegateOnCaptcha(r); } }
@Test void constructorForCaptchaLess() { final Loan mockedLoan = LoanDescriptorTest.mockLoan(Rating.AAAAA); final LoanDescriptor ld = new LoanDescriptor(mockedLoan); assertSoftly(softly -> { softly.assertThat(ld.item()).isSameAs(mockedLoan); softly.assertThat(ld.getLoanCaptchaProtectionEndDateTime()).isEmpty(); }); }
@Disabled("Looks like CAPTCHA is disabled for now. Let's wait and see if it comes back.") @Test void constructorForCaptcha() { final Loan mockedLoan = LoanDescriptorTest.mockLoan(); final LoanDescriptor ld = new LoanDescriptor(mockedLoan); assertSoftly(softly -> { softly.assertThat(ld.item()).isSameAs(mockedLoan); softly.assertThat(ld.getLoanCaptchaProtectionEndDateTime()) .isPresent() .contains(mockedLoan.getDatePublished().plus(Settings.INSTANCE.getCaptchaDelay())); }); }