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()) //
|
||||
|
||||
Reference in New Issue
Block a user