FINERACT-2277: Deprecate findExistingReversedTransactionIds and fetch only the ids from database instead

This commit is contained in:
mariiaKraievska
2025-05-26 14:41:32 +02:00
committed by Adam Saghy
parent 13e4c8b55d
commit 8b86229a3e
15 changed files with 52 additions and 51 deletions
@@ -760,14 +760,6 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom<Long> {
return maturityDate;
}
public List<Long> findExistingReversedTransactionIds() {
return getLoanTransactions().stream() //
.filter(LoanTransaction::isReversed) //
.filter(loanTransaction -> loanTransaction.getId() != null) //
.map(LoanTransaction::getId) //
.collect(Collectors.toList());
}
public List<LoanDisbursementDetails> getDisbursedLoanDisbursementDetails() {
return getDisbursementDetails().stream() //
.filter(it -> it.actualDisbursementDate() != null) //
@@ -105,4 +105,12 @@ public interface LoanTransactionRepository extends JpaRepository<LoanTransaction
""")
List<Long> findTransactionIdsByLoan(@Param("loan") Loan loan);
@Query("""
SELECT lt.id FROM LoanTransaction lt
WHERE lt.loan = :loan
AND lt.id IS NOT NULL
AND lt.reversed = true
""")
List<Long> findReversedTransactionIdsByLoan(@Param("loan") Loan loan);
}
@@ -104,7 +104,7 @@ public class LoanChargeService {
final List<Long> existingReversedTransactionIds, final LoanTransaction paymentTransaction, final Integer installmentNumber) {
loanChargeValidator.validateChargePaymentNotInFuture(paymentTransaction);
existingTransactionIds.addAll(loanTransactionRepository.findTransactionIdsByLoan(loan));
existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds());
existingReversedTransactionIds.addAll(loanTransactionRepository.findReversedTransactionIdsByLoan(loan));
LoanCharge charge = null;
for (final LoanCharge loanCharge : loan.getCharges()) {
if (loanCharge.isActive() && chargeId.equals(loanCharge.getId())) {
@@ -41,7 +41,7 @@ public class LoanRefundService {
public void makeRefund(final Loan loan, final LoanTransaction loanTransaction, final List<Long> existingTransactionIds,
final List<Long> existingReversedTransactionIds) {
existingTransactionIds.addAll(loanTransactionRepository.findTransactionIdsByLoan(loan));
existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds());
existingReversedTransactionIds.addAll(loanTransactionRepository.findReversedTransactionIdsByLoan(loan));
loanRefundValidator.validateTransferRefund(loan, loanTransaction);
@@ -62,7 +62,7 @@ public class LoanRefundService {
public void makeRefundForActiveLoan(final Loan loan, final LoanTransaction loanTransaction, final List<Long> existingTransactionIds,
final List<Long> existingReversedTransactionIds) {
existingTransactionIds.addAll(loanTransactionRepository.findTransactionIdsByLoan(loan));
existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds());
existingReversedTransactionIds.addAll(loanTransactionRepository.findReversedTransactionIdsByLoan(loan));
handleRefundTransaction(loan, loanTransaction);
}
@@ -72,7 +72,7 @@ public class LoanRefundService {
loanRefundValidator.validateCreditBalanceRefund(loan, newCreditBalanceRefundTransaction);
existingTransactionIds.addAll(loanTransactionRepository.findTransactionIdsByLoan(loan));
existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds());
existingReversedTransactionIds.addAll(loanTransactionRepository.findReversedTransactionIdsByLoan(loan));
loan.getLoanTransactions().add(newCreditBalanceRefundTransaction);
@@ -72,7 +72,7 @@ public class LoanScheduleService {
public void recalculateScheduleFromLastTransaction(final Loan loan, final ScheduleGeneratorDTO generatorDTO,
final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds) {
existingTransactionIds.addAll(loanTransactionRepository.findTransactionIdsByLoan(loan));
existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds());
existingReversedTransactionIds.addAll(loanTransactionRepository.findReversedTransactionIdsByLoan(loan));
if (!loan.isProgressiveSchedule()) {
if (loan.isInterestBearingAndInterestRecalculationEnabled() && !loan.isChargedOff()) {
regenerateRepaymentScheduleWithInterestRecalculation(loan, generatorDTO);