From 1331073679e277c137971bec8fa339606dfde809 Mon Sep 17 00:00:00 2001 From: Ruchi Dhamankar Date: Tue, 15 Nov 2022 21:32:55 +0530 Subject: [PATCH] FINERACT-1734-Repayment-due-event --- ...CheckLoanRepaymentOverdueBusinessStep.java | 21 ++++--- ...kLoanRepaymentOverdueBusinessStepTest.java | 55 ++++++++++++++----- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStep.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStep.java index fe56c47d6..d30d507d4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStep.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStep.java @@ -19,22 +19,20 @@ package org.apache.fineract.cob.loan; import java.time.LocalDate; -import java.util.Collection; +import java.util.List; import lombok.RequiredArgsConstructor; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRepaymentOverdueBusinessEvent; import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; import org.apache.fineract.portfolio.loanaccount.domain.Loan; -import org.apache.fineract.portfolio.loanaccount.loanschedule.data.OverdueLoanScheduleData; -import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService; +import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment; import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessStep { - private final LoanReadPlatformService loanReadPlatformService; private final ConfigurationDomainService configurationDomainService; private final BusinessEventNotifierService businessEventNotifierService; @@ -42,13 +40,14 @@ public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessSte public Loan execute(Loan loan) { Long numberOfDaysAfterDueDateToRaiseEvent = configurationDomainService.retrieveRepaymentOverdueDays(); final LocalDate currentDate = DateUtils.getBusinessLocalDate(); - final Collection overdueInstallmentsForLoan = loanReadPlatformService - .retrieveAllOverdueInstallmentsForLoan(loan); - for (OverdueLoanScheduleData overdueInstallment : overdueInstallmentsForLoan) { - LocalDate installmentDueDate = LocalDate.parse(overdueInstallment.getDueDate()); - if (installmentDueDate.plusDays(numberOfDaysAfterDueDateToRaiseEvent).equals(currentDate)) { - businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentOverdueBusinessEvent(loan)); - break; + final List loanRepaymentScheduleInstallments = loan.getRepaymentScheduleInstallments(); + for (LoanRepaymentScheduleInstallment repaymentSchedule : loanRepaymentScheduleInstallments) { + if (!repaymentSchedule.isObligationsMet()) { + LocalDate installmentDueDate = repaymentSchedule.getDueDate(); + if (installmentDueDate.plusDays(numberOfDaysAfterDueDateToRaiseEvent).equals(currentDate)) { + businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentOverdueBusinessEvent(loan)); + break; + } } } return loan; diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStepTest.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStepTest.java index 6b34207e9..252e01d96 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStepTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStepTest.java @@ -28,8 +28,9 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.time.ZoneId; import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; @@ -39,8 +40,7 @@ import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRepaymentOverdueBusinessEvent; import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; import org.apache.fineract.portfolio.loanaccount.domain.Loan; -import org.apache.fineract.portfolio.loanaccount.loanschedule.data.OverdueLoanScheduleData; -import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService; +import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -52,8 +52,6 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) public class CheckLoanRepaymentOverdueBusinessStepTest { - @Mock - private LoanReadPlatformService loanReadPlatformService; @Mock private ConfigurationDomainService configurationDomainService; @Mock @@ -65,8 +63,7 @@ public class CheckLoanRepaymentOverdueBusinessStepTest { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); - underTest = new CheckLoanRepaymentOverdueBusinessStep(loanReadPlatformService, configurationDomainService, - businessEventNotifierService); + underTest = new CheckLoanRepaymentOverdueBusinessStep(configurationDomainService, businessEventNotifierService); } @Test @@ -76,11 +73,13 @@ public class CheckLoanRepaymentOverdueBusinessStepTest { // given when(configurationDomainService.retrieveRepaymentOverdueDays()).thenReturn(1L); LocalDate loanInstallmentRepaymentDueDate = DateUtils.getBusinessLocalDate().minusDays(1); - Collection overdueInstallmentsForLoan = Arrays - .asList(new OverdueLoanScheduleData(1L, 1L, loanInstallmentRepaymentDueDate.toString(), BigDecimal.valueOf(0.0), "", "", - BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), 1)); - when(loanReadPlatformService.retrieveAllOverdueInstallmentsForLoan(any())).thenReturn(overdueInstallmentsForLoan); Loan loanForProcessing = Mockito.mock(Loan.class); + List loanRepaymentScheduleInstallments = Arrays + .asList(new LoanRepaymentScheduleInstallment(loanForProcessing, 1, LocalDate.now(ZoneId.systemDefault()), + loanInstallmentRepaymentDueDate, BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), + BigDecimal.valueOf(0.0), false, new HashSet<>(), BigDecimal.valueOf(0.0))); + when(loanForProcessing.getRepaymentScheduleInstallments()).thenReturn(loanRepaymentScheduleInstallments); + // when Loan processedLoan = underTest.execute(loanForProcessing); // then @@ -95,11 +94,12 @@ public class CheckLoanRepaymentOverdueBusinessStepTest { // given when(configurationDomainService.retrieveRepaymentOverdueDays()).thenReturn(1L); LocalDate loanInstallmentRepaymentDueDateBefore5Days = DateUtils.getBusinessLocalDate().minusDays(5); - Collection overdueInstallmentsForLoan = Arrays - .asList(new OverdueLoanScheduleData(1L, 1L, loanInstallmentRepaymentDueDateBefore5Days.toString(), BigDecimal.valueOf(0.0), - "", "", BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), 1)); - when(loanReadPlatformService.retrieveAllOverdueInstallmentsForLoan(any())).thenReturn(overdueInstallmentsForLoan); Loan loanForProcessing = Mockito.mock(Loan.class); + List loanRepaymentScheduleInstallments = Arrays + .asList(new LoanRepaymentScheduleInstallment(loanForProcessing, 1, LocalDate.now(ZoneId.systemDefault()), + loanInstallmentRepaymentDueDateBefore5Days, BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), + BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), false, new HashSet<>(), BigDecimal.valueOf(0.0))); + when(loanForProcessing.getRepaymentScheduleInstallments()).thenReturn(loanRepaymentScheduleInstallments); // when Loan processedLoan = underTest.execute(loanForProcessing); // then @@ -107,4 +107,29 @@ public class CheckLoanRepaymentOverdueBusinessStepTest { assertEquals(processedLoan, loanForProcessing); } + + @Test + public void givenLoanWithInstallmentOverdueAfterConfiguredDaysButInstallmentPaidOffWhenStepExecutionThenNoBusinessEvent() { + ArgumentCaptor loanRepaymentOverdueBusinessEventArgumentCaptor = ArgumentCaptor + .forClass(LoanRepaymentOverdueBusinessEvent.class); + // given + when(configurationDomainService.retrieveRepaymentOverdueDays()).thenReturn(1L); + LocalDate loanInstallmentRepaymentDueDate = DateUtils.getBusinessLocalDate().minusDays(1); + Loan loanForProcessing = Mockito.mock(Loan.class); + LoanRepaymentScheduleInstallment repaymentInstallmentPaidOff = new LoanRepaymentScheduleInstallment(loanForProcessing, 1, + LocalDate.now(ZoneId.systemDefault()), loanInstallmentRepaymentDueDate, BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), + BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), false, new HashSet<>(), BigDecimal.valueOf(0.0)); + + repaymentInstallmentPaidOff.updateObligationMet(true); + + List loanRepaymentScheduleInstallments = Arrays.asList(repaymentInstallmentPaidOff); + when(loanForProcessing.getRepaymentScheduleInstallments()).thenReturn(loanRepaymentScheduleInstallments); + + // when + Loan processedLoan = underTest.execute(loanForProcessing); + // then + verify(businessEventNotifierService, times(0)).notifyPostBusinessEvent(any()); + assertEquals(processedLoan, loanForProcessing); + } + }