FINERACT-2418: Extend disbursal and reage events with changed terms flag
This commit is contained in:
committed by
Adam Saghy
parent
136a966fc3
commit
1feb1d730f
+1
@@ -33,6 +33,7 @@ public interface LoanTransactionDataMapper {
|
||||
@Mapping(target = "customData", ignore = true)
|
||||
@Mapping(target = "reversed", expression = "java(isReversed(source))")
|
||||
@Mapping(target = "originators", ignore = true)
|
||||
@Mapping(target = "flags", ignore = true)
|
||||
LoanTransactionDataV1 map(LoanTransactionData source);
|
||||
|
||||
default boolean isReversed(LoanTransactionData source) {
|
||||
|
||||
+7
@@ -23,8 +23,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.apache.avro.generic.GenericContainer;
|
||||
import org.apache.fineract.avro.generator.ByteBufferSerializable;
|
||||
import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1;
|
||||
import org.apache.fineract.avro.loan.v1.LoanTransactionFlagsDataV1;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionFlagsData;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanTransactionDataMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.AbstractBusinessEventWithCustomDataSerializer;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer;
|
||||
@@ -60,6 +62,11 @@ public class LoanTransactionBusinessEventSerializer extends AbstractBusinessEven
|
||||
final LoanTransactionDataV1 result = loanTransactionMapper.map(transactionData);
|
||||
result.setCustomData(collectCustomData(event));
|
||||
|
||||
LoanTransactionFlagsData flags = event.getFlags();
|
||||
if (flags != null) {
|
||||
result.setFlags(LoanTransactionFlagsDataV1.newBuilder().setChangedTerms(flags.changedTerms()).build());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+16
-5
@@ -95,6 +95,7 @@ import org.apache.fineract.infrastructure.event.business.domain.loan.transaction
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanChargeOffPreBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanDisbursalTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionFlagsData;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionInterestPaymentWaiverPostBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionInterestPaymentWaiverPreBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionInterestRefundPostBusinessEvent;
|
||||
@@ -368,6 +369,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
final Locale locale = command.extractLocale();
|
||||
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale);
|
||||
|
||||
final long termsBefore = loan.getTermsCount();
|
||||
|
||||
if (canDisburse(loan)) {
|
||||
// Get netDisbursalAmount from disbursal screen field.
|
||||
final BigDecimal netDisbursalAmount = command
|
||||
@@ -511,7 +514,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
.filter(e -> LoanTransactionType.DISBURSEMENT.equals(e.getTypeOf())).findFirst().orElseThrow();
|
||||
disbursalTransactionId = disbursalTransaction.getId();
|
||||
disbursalTransactionExternalId = disbursalTransaction.getExternalId();
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanDisbursalTransactionBusinessEvent(disbursalTransaction));
|
||||
final long termsAfter = loan.getTermsCount();
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanDisbursalTransactionBusinessEvent(disbursalTransaction,
|
||||
new LoanTransactionFlagsData(termsAfter != termsBefore)));
|
||||
}
|
||||
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan));
|
||||
@@ -757,17 +762,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
Money disburseAmount = loanDisbursementService.adjustDisburseAmount(loan, command, actualDisbursementDate);
|
||||
boolean recalculateSchedule = amountBeforeAdjust.isNotEqualTo(loan.getPrincipal());
|
||||
final ExternalId txnExternalId = externalIdFactory.createFromCommand(command, LoanApiConstants.externalIdParameterName);
|
||||
final long termsBefore = loan.getTermsCount();
|
||||
LoanTransaction disbursementTransaction = null;
|
||||
if (isAccountTransfer) {
|
||||
disburseLoanToSavings(loan, command, disburseAmount, paymentDetail);
|
||||
} else {
|
||||
LoanTransaction disbursementTransaction = LoanTransaction.disbursement(loan, disburseAmount, paymentDetail,
|
||||
actualDisbursementDate, txnExternalId, loan.getTotalOverpaidAsMoney());
|
||||
disbursementTransaction = LoanTransaction.disbursement(loan, disburseAmount, paymentDetail, actualDisbursementDate,
|
||||
txnExternalId, loan.getTotalOverpaidAsMoney());
|
||||
disbursementTransaction.updateLoan(loan);
|
||||
loan.addLoanTransaction(disbursementTransaction);
|
||||
loanTransactionRepository.saveAndFlush(disbursementTransaction);
|
||||
journalEntryPoster.postJournalEntriesForLoanTransaction(disbursementTransaction, false, false);
|
||||
businessEventNotifierService
|
||||
.notifyPostBusinessEvent(new LoanDisbursalTransactionBusinessEvent(disbursementTransaction));
|
||||
}
|
||||
LocalDate recalculateFrom = null;
|
||||
final ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom);
|
||||
@@ -779,6 +784,12 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
}
|
||||
disburseLoan(command, configurationDomainService.isPaymentTypeApplicableForDisbursementCharge(), paymentDetail, loan,
|
||||
currentUser, changes, scheduleGeneratorDTO);
|
||||
if (disbursementTransaction != null) {
|
||||
final long termsAfter = loan.getTermsCount();
|
||||
final LoanTransactionFlagsData additionalDisbursalFlags = new LoanTransactionFlagsData(termsAfter != termsBefore);
|
||||
businessEventNotifierService.notifyPostBusinessEvent(
|
||||
new LoanDisbursalTransactionBusinessEvent(disbursementTransaction, additionalDisbursalFlags));
|
||||
}
|
||||
|
||||
loanAccrualsProcessingService.reprocessExistingAccruals(loan, true);
|
||||
|
||||
|
||||
+7
-1
@@ -44,6 +44,7 @@ import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
|
||||
import org.apache.fineract.infrastructure.core.service.MathUtil;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.reaging.LoanReAgeBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.reaging.LoanUndoReAgeBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionFlagsData;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reaging.LoanReAgeTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reaging.LoanUndoReAgeTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||
@@ -105,6 +106,8 @@ public class LoanReAgingService {
|
||||
reAgingValidator.validateReAge(loan, command);
|
||||
BigDecimal userProvidedTxnAmount = command.bigDecimalValueOfParameterNamed(LoanReAgingApiConstants.transactionAmountParamName);
|
||||
|
||||
final long termsBefore = loan.getTermsCount();
|
||||
|
||||
final LoanTransaction reAgeTransaction = createReAgeTransaction(loan, command);
|
||||
processReAgeTransaction(loan, reAgeTransaction, true);
|
||||
validateUserProvidedTransactionAmount(userProvidedTxnAmount, reAgeTransaction);
|
||||
@@ -116,9 +119,12 @@ public class LoanReAgingService {
|
||||
changes.put(LoanReAgingApiConstants.dateFormatParameterName, command.dateFormat());
|
||||
persistNote(loan, command, changes);
|
||||
|
||||
final long termsAfter = loan.getTermsCount();
|
||||
|
||||
// delinquency recalculation will be triggered by the event in a decoupled way via a listener
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanReAgeBusinessEvent(loan));
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanReAgeTransactionBusinessEvent(reAgeTransaction));
|
||||
businessEventNotifierService.notifyPostBusinessEvent(
|
||||
new LoanReAgeTransactionBusinessEvent(reAgeTransaction, new LoanTransactionFlagsData(termsAfter != termsBefore)));
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
.withEntityId(reAgeTransaction.getId()) //
|
||||
|
||||
+62
@@ -21,6 +21,8 @@ package org.apache.fineract.infrastructure.event.external.service.serialization.
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -32,7 +34,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanDisbursalTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionFlagsData;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanTransactionDataMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.ExternalEventCustomDataSerializer;
|
||||
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData;
|
||||
@@ -133,4 +137,62 @@ class LoanTransactionBusinessEventSerializerTest {
|
||||
assertEquals("test_data_for_loan_transaction_2", new String(customData.get("test_key_2").array(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransactionFlagsSerializationWithChangedTerms() {
|
||||
final long loanId = 1;
|
||||
final long transactionId = 2;
|
||||
|
||||
final Loan loan = mock(Loan.class);
|
||||
final LoanTransaction loanTransaction = mock(LoanTransaction.class);
|
||||
final LoanTransactionData transactionData = mock(LoanTransactionData.class);
|
||||
|
||||
when(loan.getId()).thenReturn(loanId);
|
||||
when(loanTransaction.getId()).thenReturn(transactionId);
|
||||
when(loanTransaction.getLoan()).thenReturn(loan);
|
||||
|
||||
final LoanTransactionFlagsData flags = new LoanTransactionFlagsData(true);
|
||||
final LoanDisbursalTransactionBusinessEvent event = new LoanDisbursalTransactionBusinessEvent(loanTransaction, flags);
|
||||
|
||||
when(loanReadPlatformService.retrieveLoanTransaction(loanId, transactionId)).thenReturn(transactionData);
|
||||
when(loanChargePaidByReadService.fetchLoanChargesPaidByDataTransactionId(anyLong())).thenReturn(new ArrayList<>());
|
||||
|
||||
final LoanTransactionDataV1 expectedAvroData = LoanTransactionDataV1.newBuilder().setId(transactionId).setLoanId(loanId)
|
||||
.setCustomData(new HashMap<>()).build();
|
||||
when(loanTransactionMapper.map(any(LoanTransactionData.class))).thenReturn(expectedAvroData);
|
||||
|
||||
final LoanTransactionDataV1 result = (LoanTransactionDataV1) serializer.toAvroDTO(event);
|
||||
|
||||
assertNotNull(result);
|
||||
assertNotNull(result.getFlags());
|
||||
assertTrue(result.getFlags().getChangedTerms());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransactionWithoutFlagsHasNullFlags() {
|
||||
final long loanId = 1;
|
||||
final long transactionId = 2;
|
||||
|
||||
final Loan loan = mock(Loan.class);
|
||||
final LoanTransaction loanTransaction = mock(LoanTransaction.class);
|
||||
final LoanTransactionData transactionData = mock(LoanTransactionData.class);
|
||||
|
||||
when(loan.getId()).thenReturn(loanId);
|
||||
when(loanTransaction.getId()).thenReturn(transactionId);
|
||||
when(loanTransaction.getLoan()).thenReturn(loan);
|
||||
|
||||
final LoanDisbursalTransactionBusinessEvent event = new LoanDisbursalTransactionBusinessEvent(loanTransaction);
|
||||
|
||||
when(loanReadPlatformService.retrieveLoanTransaction(loanId, transactionId)).thenReturn(transactionData);
|
||||
when(loanChargePaidByReadService.fetchLoanChargesPaidByDataTransactionId(anyLong())).thenReturn(new ArrayList<>());
|
||||
|
||||
final LoanTransactionDataV1 expectedAvroData = LoanTransactionDataV1.newBuilder().setId(transactionId).setLoanId(loanId)
|
||||
.setCustomData(new HashMap<>()).build();
|
||||
when(loanTransactionMapper.map(any(LoanTransactionData.class))).thenReturn(expectedAvroData);
|
||||
|
||||
final LoanTransactionDataV1 result = (LoanTransactionDataV1) serializer.toAvroDTO(event);
|
||||
|
||||
assertNotNull(result);
|
||||
assertNull(result.getFlags());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user