Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@
"items": "org.apache.fineract.avro.loan.v1.OriginatorDetailsV1"
}
]
},
{
"default": null,
"name": "flags",
"doc": "Optional flags associated with this transaction event",
"type": [
"null",
"org.apache.fineract.avro.loan.v1.LoanTransactionFlagsDataV1"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "LoanTransactionFlagsDataV1",
"namespace": "org.apache.fineract.avro.loan.v1",
"doc": "Optional flags associated with a loan transaction event",
"type": "record",
"fields": [{
"default": null,
"name": "changedTerms",
"doc": "True if the transaction changed the number of loan repayment terms (installments excluding downpayment and additional)",
"type": [
"null",
"boolean"
]
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.test.messaging.event.loan.transaction;

public class LoanReAgeTransactionEvent extends AbstractLoanTransactionEvent {

@Override
public String getEventName() {
return "LoanReAgeTransactionBusinessEvent";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.avro.loan.v1.LoanTransactionFlagsDataV1;
import org.apache.fineract.client.feign.FineractFeignClient;
import org.apache.fineract.client.feign.util.CallFailedRuntimeException;
import org.apache.fineract.client.models.LoanScheduleData;
Expand All @@ -49,6 +50,7 @@
import org.apache.fineract.test.helper.Utils;
import org.apache.fineract.test.messaging.EventAssertion;
import org.apache.fineract.test.messaging.event.loan.LoanReAgeEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanReAgeTransactionEvent;
import org.apache.fineract.test.stepdef.AbstractStepDef;
import org.apache.fineract.test.support.TestContextKey;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -414,4 +416,20 @@ public void checkCreateLoanReAgeFailure(DataTable table, String errorMessage) {
assertThat(exception.getDeveloperMessage()).contains(errorMessage);
}

@Then("LoanReAgeTransactionBusinessEvent has changedTerms {string}")
public void checkReAgeTransactionEventChangedTerms(final String expectedChangedTerms) {
final PostLoansLoanIdTransactionsResponse reAgingResponse = testContext().get(TestContextKey.LOAN_REAGING_RESPONSE);
Assertions.assertNotNull(reAgingResponse);
final Long transactionId = reAgingResponse.getResourceId();
Assertions.assertNotNull(transactionId);

final Boolean expectedValue = "null".equalsIgnoreCase(expectedChangedTerms) ? null : Boolean.valueOf(expectedChangedTerms);

eventAssertion.assertEvent(LoanReAgeTransactionEvent.class, transactionId).extractingData(loanTransactionDataV1 -> {
final LoanTransactionFlagsDataV1 flags = loanTransactionDataV1.getFlags();
final Boolean actualChangedTerms = flags == null ? null : flags.getChangedTerms();
assertThat(actualChangedTerms).as("changedTerms in LoanReAgeTransactionBusinessEvent").isEqualTo(expectedValue);
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.fineract.avro.loan.v1.LoanStatusEnumDataV1;
import org.apache.fineract.avro.loan.v1.LoanTransactionAdjustmentDataV1;
import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1;
import org.apache.fineract.avro.loan.v1.LoanTransactionFlagsDataV1;
import org.apache.fineract.client.feign.FineractFeignClient;
import org.apache.fineract.client.feign.util.CallFailedRuntimeException;
import org.apache.fineract.client.models.AdvancedPaymentData;
Expand Down Expand Up @@ -162,6 +163,7 @@
import org.apache.fineract.test.messaging.event.loan.transaction.LoanChargeAdjustmentPostBusinessEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanChargeOffEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanChargeOffUndoEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanDisbursalTransactionEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanTransactionAccrualActivityPostEvent;
import org.apache.fineract.test.messaging.event.loan.transaction.LoanTransactionContractTerminationPostBusinessEvent;
import org.apache.fineract.test.messaging.store.EventStore;
Expand Down Expand Up @@ -5942,4 +5944,35 @@ public static AdvancedPaymentData editPaymentAllocationFutureInstallment(String

return advancedPaymentData;
}

@When("Admin disburses the loan on {string} with {string} EUR transaction amount")
public void disburseLoanForEventVerification(String actualDisbursementDate, String transactionAmount) {
PostLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
assertNotNull(loanResponse);
long loanId = loanResponse.getLoanId();

PostLoansLoanIdRequest disburseRequest = LoanRequestFactory.defaultLoanDisburseRequest()
.actualDisbursementDate(actualDisbursementDate).transactionAmount(new BigDecimal(transactionAmount));

PostLoansLoanIdResponse loanDisburseResponse = ok(
() -> fineractClient.loans().stateTransitions(loanId, disburseRequest, Map.of("command", "disburse")));
testContext().set(TestContextKey.LOAN_DISBURSE_RESPONSE, loanDisburseResponse);
}

@Then("LoanDisbursalTransactionBusinessEvent has changedTerms {string}")
public void checkDisbursalTransactionEventChangedTerms(final String expectedChangedTerms) {
final PostLoansLoanIdResponse disburseResponse = testContext().get(TestContextKey.LOAN_DISBURSE_RESPONSE);
assertNotNull(disburseResponse);
final Long transactionId = disburseResponse.getSubResourceId();
assertNotNull(transactionId);

final Boolean expectedValue = "null".equalsIgnoreCase(expectedChangedTerms) ? null : Boolean.valueOf(expectedChangedTerms);

eventAssertion.assertEvent(LoanDisbursalTransactionEvent.class, transactionId).extractingData(loanTransactionDataV1 -> {
final LoanTransactionFlagsDataV1 flags = loanTransactionDataV1.getFlags();
final Boolean actualChangedTerms = flags == null ? null : flags.getChangedTerms();
assertThat(actualChangedTerms).as("changedTerms in LoanDisbursalTransactionBusinessEvent").isEqualTo(expectedValue);
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9021,4 +9021,41 @@ Feature: Loan
| 01 January 2025 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false |
| 01 February 2025 | Disbursement | 500.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1500.0 | false | false |
| 01 February 2025 | Repayment | 1525.89 | 1500.0 | 25.89 | 0.0 | 0.0 | 0.0 | false | false |
| 01 February 2025 | Accrual | 25.89 | 0.0 | 25.89 | 0.0 | 0.0 | 0.0 | false | false |
| 01 February 2025 | Accrual | 25.89 | 0.0 | 25.89 | 0.0 | 0.0 | 0.0 | false | false |

Scenario: Verify that changedTerms is false in LoanDisbursalTransactionBusinessEvent for initial disbursement
When Admin sets the business date to "01 January 2024"
When Admin creates a client with random data
When Admin creates a fully customized loan with the following data:
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
| LP2_ADV_CUSTOM_PMT_ALLOC_PROGRESSIVE_LOAN_SCHEDULE_HORIZONTAL | 01 January 2024 | 1000 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 45 | DAYS | 15 | DAYS | 3 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
And Admin successfully approves the loan on "01 January 2024" with "1000" amount and expected disbursement date on "01 January 2024"
When Admin disburses the loan on "01 January 2024" with "1000" EUR transaction amount
Then LoanDisbursalTransactionBusinessEvent has changedTerms "false"

Scenario: Verify that changedTerms is true in LoanDisbursalTransactionBusinessEvent when additional disbursement adds new terms
When Admin sets the business date to "01 January 2024"
When Admin creates a client with random data
When Admin creates a fully customized loan with the following data:
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
| LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_RECALC_DAILY_MULTIDISBURSE_FULL_TERM_TRANCHE | 01 January 2024 | 200 | 9.4822 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
And Admin successfully approves the loan on "01 January 2024" with "200" amount and expected disbursement date on "01 January 2024"
When Admin disburses the loan on "01 January 2024" with "100" EUR transaction amount
Then LoanDisbursalTransactionBusinessEvent has changedTerms "false"
When Admin sets the business date to "01 February 2024"
When Admin disburses the loan on "01 February 2024" with "100" EUR transaction amount
Then LoanDisbursalTransactionBusinessEvent has changedTerms "true"

Scenario: Verify that changedTerms is false in LoanDisbursalTransactionBusinessEvent when additional disbursement does not change terms
When Admin sets the business date to "01 January 2024"
When Admin creates a client with random data
When Admin set "LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_MULTIDISBURSE" loan product "DEFAULT" transaction type to "NEXT_INSTALLMENT" future installment allocation rule
When Admin creates a fully customized loan with the following data:
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
| LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_MULTIDISBURSE | 01 January 2024 | 300 | 9.4822 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
And Admin successfully approves the loan on "01 January 2024" with "300" amount and expected disbursement date on "01 January 2024"
When Admin disburses the loan on "01 January 2024" with "100" EUR transaction amount
Then LoanDisbursalTransactionBusinessEvent has changedTerms "false"
When Admin sets the business date to "08 January 2024"
When Admin disburses the loan on "08 January 2024" with "200" EUR transaction amount
Then LoanDisbursalTransactionBusinessEvent has changedTerms "false"
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Feature: LoanReAging
| 01 January 2024 | Down Payment | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 750.0 | false |
| 20 February 2024 | Re-age | 750.0 | 750.0 | 0.0 | 0.0 | 0.0 | 0.0 | false |
Then Admin checks that delinquency range is: "NO_DELINQUENCY" and has delinquentDate ""

Then LoanReAgeTransactionBusinessEvent has changedTerms "true"
When Loan Pay-off is made on "20 February 2024"
Then Loan is closed with zero outstanding balance and it's all installments have obligations met

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public LoanDisbursalTransactionBusinessEvent(LoanTransaction value) {
super(value);
}

public LoanDisbursalTransactionBusinessEvent(LoanTransaction value, LoanTransactionFlagsData flags) {
super(value, flags);
}

@Override
public String getType() {
return TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@
*/
package org.apache.fineract.infrastructure.event.business.domain.loan.transaction;

import lombok.Getter;
import org.apache.fineract.infrastructure.event.business.domain.AbstractBusinessEvent;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;

@Getter
public abstract class LoanTransactionBusinessEvent extends AbstractBusinessEvent<LoanTransaction> {

private static final String CATEGORY = "Loan";

private final LoanTransactionFlagsData flags;

public LoanTransactionBusinessEvent(LoanTransaction value) {
this(value, null);
}

public LoanTransactionBusinessEvent(LoanTransaction value, LoanTransactionFlagsData flags) {
super(value);
this.flags = flags;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.event.business.domain.loan.transaction;

public record LoanTransactionFlagsData(boolean changedTerms) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reaging;

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.portfolio.loanaccount.domain.LoanTransaction;

public class LoanReAgeTransactionBusinessEvent extends LoanTransactionBusinessEvent {
Expand All @@ -29,6 +30,10 @@ public LoanReAgeTransactionBusinessEvent(LoanTransaction value) {
super(value);
}

public LoanReAgeTransactionBusinessEvent(LoanTransaction value, LoanTransactionFlagsData flags) {
super(value, flags);
}

@Override
public String getType() {
return TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
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;
Expand Down Expand Up @@ -60,6 +62,11 @@ public <T> ByteBufferSerializable toAvroDTO(BusinessEvent<T> rawEvent) {
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;
}

Expand Down
Loading