Skip to content

Commit 00b1ae1

Browse files
committed
FINERACT-2318: add LoanApplicationModifiedBusinessEvent & LoanWithdrawnByApplicantBusinessEvent
1 parent 70eb2ad commit 00b1ae1

File tree

8 files changed

+208
-21
lines changed

8 files changed

+208
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.infrastructure.event.business.domain.loan;
20+
21+
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
22+
23+
public class LoanApplicationModifiedBusinessEvent extends LoanBusinessEvent {
24+
25+
private static final String TYPE = "LoanApplicationModifiedBusinessEvent";
26+
27+
public LoanApplicationModifiedBusinessEvent(Loan value) {
28+
super(value);
29+
}
30+
31+
@Override
32+
public String getType() {
33+
return TYPE;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.infrastructure.event.business.domain.loan;
20+
21+
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
22+
23+
public class LoanWithdrawnByApplicantBusinessEvent extends LoanBusinessEvent {
24+
25+
private static final String TYPE = "LoanWithdrawnByApplicantBusinessEvent";
26+
27+
public LoanWithdrawnByApplicantBusinessEvent(Loan value) {
28+
super(value);
29+
}
30+
31+
@Override
32+
public String getType() {
33+
return TYPE;
34+
}
35+
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
import org.apache.fineract.infrastructure.dataqueries.data.EntityTables;
5050
import org.apache.fineract.infrastructure.dataqueries.data.StatusEnum;
5151
import org.apache.fineract.infrastructure.dataqueries.service.EntityDatatableChecksWritePlatformService;
52+
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanApplicationModifiedBusinessEvent;
5253
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanApprovedBusinessEvent;
5354
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanCreatedBusinessEvent;
5455
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRejectedBusinessEvent;
5556
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanUndoApprovalBusinessEvent;
57+
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanWithdrawnByApplicantBusinessEvent;
5658
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
5759
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
5860
import org.apache.fineract.portfolio.account.domain.AccountAssociationType;
@@ -287,6 +289,8 @@ public CommandProcessingResult modifyApplication(final Long loanId, final JsonCo
287289
createAndPersistCalendarInstanceForInterestRecalculation(loan);
288290
}
289291

292+
businessEventNotifierService.notifyPostBusinessEvent(new LoanApplicationModifiedBusinessEvent(loan));
293+
290294
return new CommandProcessingResultBuilder() //
291295
.withEntityId(loanId) //
292296
.withEntityExternalId(loan.getExternalId()) //
@@ -740,6 +744,8 @@ public CommandProcessingResult applicantWithdrawsFromApplication(final Long loan
740744
createNote(noteText, loan);
741745
}
742746

747+
businessEventNotifierService.notifyPostBusinessEvent(new LoanWithdrawnByApplicantBusinessEvent(loan));
748+
743749
return new CommandProcessingResultBuilder() //
744750
.withCommandId(command.commandId()) //
745751
.withEntityId(loan.getId()) //

fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,5 @@
205205
<include file="parts/0184_add_document_event_configuration.xml" relativeToChangelogFile="true" />
206206
<include file="parts/0185_loan_buy_down_fee.xml" relativeToChangelogFile="true" />
207207
<include file="parts/0186_add_buy_down_fee_to_loan_product.xml" relativeToChangelogFile="true" />
208+
<include file="parts/0187_add_Loan_modified_and_withdrawn_event_configuration.xml" relativeToChangelogFile="true" />
208209
</databaseChangeLog>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
25+
26+
<changeSet id="1" author="fineract">
27+
<insert tableName="m_external_event_configuration">
28+
<column name="type" value="LoanWithdrawnByApplicantBusinessEvent"/>
29+
<column name="enabled" valueBoolean="false"/>
30+
</insert>
31+
<insert tableName="m_external_event_configuration">
32+
<column name="type" value="LoanApplicationModifiedBusinessEvent"/>
33+
<column name="enabled" valueBoolean="false"/>
34+
</insert>
35+
</changeSet>
36+
</databaseChangeLog>

fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ public void givenAllConfigurationWhenValidatedThenValidationSuccessful() throws
6969
List<String> configurations = Arrays.asList("CentersCreateBusinessEvent", "ClientActivateBusinessEvent",
7070
"ClientCreateBusinessEvent", "ClientRejectBusinessEvent", "DocumentCreatedBusinessEvent", "DocumentDeletedBusinessEvent",
7171
"FixedDepositAccountCreateBusinessEvent", "GroupsCreateBusinessEvent", "LoanAcceptTransferBusinessEvent",
72-
"LoanAddChargeBusinessEvent", "LoanAdjustTransactionBusinessEvent", "LoanApplyOverdueChargeBusinessEvent",
73-
"LoanApprovedBusinessEvent", "LoanBalanceChangedBusinessEvent", "LoanChargebackTransactionBusinessEvent",
74-
"LoanChargePaymentPostBusinessEvent", "LoanChargePaymentPreBusinessEvent", "LoanChargeRefundBusinessEvent",
75-
"LoanCloseAsRescheduleBusinessEvent", "LoanCloseBusinessEvent", "LoanCreatedBusinessEvent",
72+
"LoanAddChargeBusinessEvent", "LoanAdjustTransactionBusinessEvent", "LoanApplicationModifiedBusinessEvent",
73+
"LoanApplyOverdueChargeBusinessEvent", "LoanApprovedBusinessEvent", "LoanBalanceChangedBusinessEvent",
74+
"LoanChargebackTransactionBusinessEvent", "LoanChargePaymentPostBusinessEvent", "LoanChargePaymentPreBusinessEvent",
75+
"LoanChargeRefundBusinessEvent", "LoanCloseAsRescheduleBusinessEvent", "LoanCloseBusinessEvent", "LoanCreatedBusinessEvent",
7676
"LoanCreditBalanceRefundPostBusinessEvent", "LoanCreditBalanceRefundPreBusinessEvent", "LoanDeleteChargeBusinessEvent",
7777
"LoanDisbursalBusinessEvent", "LoanDisbursalTransactionBusinessEvent", "LoanForeClosurePostBusinessEvent",
7878
"LoanForeClosurePreBusinessEvent", "LoanInitiateTransferBusinessEvent", "LoanInterestRecalculationBusinessEvent",
@@ -89,9 +89,9 @@ public void givenAllConfigurationWhenValidatedThenValidationSuccessful() throws
8989
"LoanUndoApprovalBusinessEvent", "LoanUndoDisbursalBusinessEvent", "LoanUndoLastDisbursalBusinessEvent",
9090
"LoanUndoWrittenOffBusinessEvent", "LoanUpdateChargeBusinessEvent", "LoanUpdateDisbursementDataBusinessEvent",
9191
"LoanWaiveChargeBusinessEvent", "LoanWaiveChargeUndoBusinessEvent", "LoanWaiveInterestBusinessEvent",
92-
"LoanWithdrawTransferBusinessEvent", "LoanWrittenOffPostBusinessEvent", "LoanWrittenOffPreBusinessEvent",
93-
"RecurringDepositAccountCreateBusinessEvent", "SavingsActivateBusinessEvent", "SavingsApproveBusinessEvent",
94-
"SavingsCloseBusinessEvent", "SavingsCreateBusinessEvent", "SavingsDepositBusinessEvent",
92+
"LoanWithdrawnByApplicantBusinessEvent", "LoanWithdrawTransferBusinessEvent", "LoanWrittenOffPostBusinessEvent",
93+
"LoanWrittenOffPreBusinessEvent", "RecurringDepositAccountCreateBusinessEvent", "SavingsActivateBusinessEvent",
94+
"SavingsApproveBusinessEvent", "SavingsCloseBusinessEvent", "SavingsCreateBusinessEvent", "SavingsDepositBusinessEvent",
9595
"SavingsPostInterestBusinessEvent", "SavingsRejectBusinessEvent", "SavingsWithdrawalBusinessEvent",
9696
"ShareAccountApproveBusinessEvent", "ShareAccountCreateBusinessEvent", "ShareProductDividentsCreateBusinessEvent",
9797
"LoanChargeAdjustmentPostBusinessEvent", "LoanChargeAdjustmentPreBusinessEvent", "LoanDelinquencyRangeChangeBusinessEvent",
@@ -160,17 +160,18 @@ public void givenMissingEventConfigurationWhenValidatedThenThrowException() thro
160160
"ClientActivateBusinessEvent", "ClientCreateBusinessEvent", "ClientRejectBusinessEvent", "DocumentCreatedBusinessEvent",
161161
"DocumentDeletedBusinessEvent", "FixedDepositAccountCreateBusinessEvent", "GroupsCreateBusinessEvent",
162162
"LoanAcceptTransferBusinessEvent", "LoanAddChargeBusinessEvent", "LoanAdjustTransactionBusinessEvent",
163-
"LoanApplyOverdueChargeBusinessEvent", "LoanApprovedBusinessEvent", "LoanBalanceChangedBusinessEvent",
164-
"LoanChargebackTransactionBusinessEvent", "LoanChargePaymentPostBusinessEvent", "LoanChargePaymentPreBusinessEvent",
165-
"LoanChargeRefundBusinessEvent", "LoanCloseAsRescheduleBusinessEvent", "LoanCloseBusinessEvent", "LoanCreatedBusinessEvent",
166-
"LoanCreditBalanceRefundPostBusinessEvent", "LoanCreditBalanceRefundPreBusinessEvent", "LoanDeleteChargeBusinessEvent",
167-
"LoanDisbursalBusinessEvent", "LoanDisbursalTransactionBusinessEvent", "LoanForeClosurePostBusinessEvent",
168-
"LoanForeClosurePreBusinessEvent", "LoanInitiateTransferBusinessEvent", "LoanInterestRecalculationBusinessEvent",
169-
"LoanProductCreateBusinessEvent", "LoanReassignOfficerBusinessEvent", "LoanRefundPostBusinessEvent",
170-
"LoanRefundPreBusinessEvent", "LoanRejectedBusinessEvent", "LoanRejectTransferBusinessEvent",
171-
"LoanRemoveOfficerBusinessEvent", "LoanRepaymentDueBusinessEvent", "LoanRepaymentOverdueBusinessEvent",
172-
"LoanRescheduledDueCalendarChangeBusinessEvent", "LoanRescheduledDueHolidayBusinessEvent",
173-
"LoanScheduleVariationsAddedBusinessEvent", "LoanScheduleVariationsDeletedBusinessEvent", "LoanStatusChangedBusinessEvent",
163+
"LoanApplicationModifiedBusinessEvent", "LoanApplyOverdueChargeBusinessEvent", "LoanApprovedBusinessEvent",
164+
"LoanBalanceChangedBusinessEvent", "LoanChargebackTransactionBusinessEvent", "LoanChargePaymentPostBusinessEvent",
165+
"LoanChargePaymentPreBusinessEvent", "LoanChargeRefundBusinessEvent", "LoanCloseAsRescheduleBusinessEvent",
166+
"LoanCloseBusinessEvent", "LoanCreatedBusinessEvent", "LoanCreditBalanceRefundPostBusinessEvent",
167+
"LoanCreditBalanceRefundPreBusinessEvent", "LoanDeleteChargeBusinessEvent", "LoanDisbursalBusinessEvent",
168+
"LoanDisbursalTransactionBusinessEvent", "LoanForeClosurePostBusinessEvent", "LoanForeClosurePreBusinessEvent",
169+
"LoanInitiateTransferBusinessEvent", "LoanInterestRecalculationBusinessEvent", "LoanProductCreateBusinessEvent",
170+
"LoanReassignOfficerBusinessEvent", "LoanRefundPostBusinessEvent", "LoanRefundPreBusinessEvent",
171+
"LoanRejectedBusinessEvent", "LoanRejectTransferBusinessEvent", "LoanRemoveOfficerBusinessEvent",
172+
"LoanRepaymentDueBusinessEvent", "LoanRepaymentOverdueBusinessEvent", "LoanRescheduledDueCalendarChangeBusinessEvent",
173+
"LoanRescheduledDueHolidayBusinessEvent", "LoanScheduleVariationsAddedBusinessEvent",
174+
"LoanScheduleVariationsDeletedBusinessEvent", "LoanStatusChangedBusinessEvent",
174175
"LoanTransactionGoodwillCreditPostBusinessEvent", "LoanTransactionGoodwillCreditPreBusinessEvent",
175176
"LoanTransactionMakeRepaymentPostBusinessEvent", "LoanTransactionMakeRepaymentPreBusinessEvent",
176177
"LoanTransactionMerchantIssuedRefundPostBusinessEvent", "LoanTransactionMerchantIssuedRefundPreBusinessEvent",
@@ -179,9 +180,9 @@ public void givenMissingEventConfigurationWhenValidatedThenThrowException() thro
179180
"LoanUndoApprovalBusinessEvent", "LoanUndoDisbursalBusinessEvent", "LoanUndoLastDisbursalBusinessEvent",
180181
"LoanUndoWrittenOffBusinessEvent", "LoanUpdateChargeBusinessEvent", "LoanUpdateDisbursementDataBusinessEvent",
181182
"LoanWaiveChargeBusinessEvent", "LoanWaiveChargeUndoBusinessEvent", "LoanWaiveInterestBusinessEvent",
182-
"LoanWithdrawTransferBusinessEvent", "LoanWrittenOffPostBusinessEvent", "LoanWrittenOffPreBusinessEvent",
183-
"RecurringDepositAccountCreateBusinessEvent", "SavingsActivateBusinessEvent", "SavingsApproveBusinessEvent",
184-
"SavingsCloseBusinessEvent", "SavingsCreateBusinessEvent", "SavingsDepositBusinessEvent",
183+
"LoanWithdrawnByApplicantBusinessEvent", "LoanWithdrawTransferBusinessEvent", "LoanWrittenOffPostBusinessEvent",
184+
"LoanWrittenOffPreBusinessEvent", "RecurringDepositAccountCreateBusinessEvent", "SavingsActivateBusinessEvent",
185+
"SavingsApproveBusinessEvent", "SavingsCloseBusinessEvent", "SavingsCreateBusinessEvent", "SavingsDepositBusinessEvent",
185186
"SavingsPostInterestBusinessEvent", "SavingsRejectBusinessEvent", "SavingsWithdrawalBusinessEvent",
186187
"ShareAccountApproveBusinessEvent", "ShareAccountCreateBusinessEvent", "ShareProductDividentsCreateBusinessEvent",
187188
"LoanChargeAdjustmentPostBusinessEvent", "LoanChargeAdjustmentPreBusinessEvent", "LoanDelinquencyRangeChangeBusinessEvent",

integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalBusinessEventTest.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.fineract.client.models.PostLoansRequest;
4747
import org.apache.fineract.client.models.PostLoansResponse;
4848
import org.apache.fineract.client.models.PostUpdateRescheduleLoansRequest;
49+
import org.apache.fineract.client.models.PutLoansLoanIdRequest;
4950
import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
5051
import org.apache.fineract.infrastructure.event.external.data.ExternalEventResponse;
5152
import org.apache.fineract.integrationtests.common.BusinessStepHelper;
@@ -900,6 +901,57 @@ public void testProgressiveLoanReverseReplayChargeOffEvents() {
900901
});
901902
}
902903

904+
@Test
905+
public void verifyLoanApplicationModifiedBusinessEvent01() {
906+
runAt("1 March 2024", () -> {
907+
908+
externalEventHelper.enableBusinessEvent("LoanApplicationModifiedBusinessEvent");
909+
910+
PostLoansRequest loanRequest = applyForLoanApplication(client.getClientId(), loanProductId, BigDecimal.valueOf(4000),
911+
"1 March 2023", "1 March 2024");
912+
PostLoansResponse applicationResponse = loanTransactionHelper.applyLoan(loanRequest);
913+
Long loanId = applicationResponse.getResourceId();
914+
Assertions.assertNotNull(loanId);
915+
916+
PutLoansLoanIdRequest modification = new PutLoansLoanIdRequest().clientId(client.getClientId()).productId(loanProductId)
917+
.transactionProcessingStrategyCode(DEFAULT_STRATEGY).interestRatePerPeriod(BigDecimal.valueOf(2)).repaymentEvery(1)
918+
.principal(550L).amortizationType(1).interestType(1).interestCalculationPeriodType(0)
919+
.expectedDisbursementDate("1 March 2024").repaymentFrequencyType(2).numberOfRepayments(4).loanTermFrequency(4)
920+
.loanTermFrequencyType(2).loanType("individual").dateFormat("dd MMMM yyyy").locale("en_GB");
921+
922+
loanTransactionHelper.modifyApplicationForLoan(loanId, "modify", modification);
923+
924+
List<ExternalEventDTO> modifiedEvents = ExternalEventHelper.getAllExternalEvents(requestSpec, responseSpec).stream()
925+
.filter(e -> "LoanApplicationModifiedBusinessEvent".equals(e.getType())).toList();
926+
927+
Assertions.assertEquals(1, modifiedEvents.size());
928+
ExternalEventDTO event = modifiedEvents.get(0);
929+
930+
Assertions.assertEquals(550.0D, event.getPayLoad().get("principal")); // the new principal
931+
});
932+
}
933+
934+
@Test
935+
public void verifyLoanWithdrawnByApplicantBusinessEvent01() {
936+
runAt("01 March 2024", () -> {
937+
938+
externalEventHelper.enableBusinessEvent("LoanWithdrawnByApplicantBusinessEvent");
939+
940+
PostLoansRequest loanRequest = applyForLoanApplication(client.getClientId(), loanProductId, BigDecimal.valueOf(4000),
941+
"1 March 2023", "01 March 2024");
942+
PostLoansResponse applicationResponse = loanTransactionHelper.applyLoan(loanRequest);
943+
Long loanId = applicationResponse.getLoanId();
944+
Assertions.assertNotNull(loanId);
945+
946+
loanTransactionHelper.withdrawLoanApplicationByClient("01 March 2024", loanId.intValue());
947+
948+
List<ExternalEventDTO> events = ExternalEventHelper.getAllExternalEvents(requestSpec, responseSpec).stream()
949+
.filter(e -> "LoanWithdrawnByApplicantBusinessEvent".equals(e.getType())).toList();
950+
951+
Assertions.assertEquals(1, events.size());
952+
});
953+
}
954+
903955
@Nested
904956
class ExternalIdGenerationTest {
905957

@@ -1054,6 +1106,17 @@ private static Long applyForLoanApplicationWithInterest(final Long clientId, fin
10541106
return loanId;
10551107
}
10561108

1109+
private static PostLoansRequest applyForLoanApplication(final Long clientId, final Long loanProductId, BigDecimal principal,
1110+
String submittedOnDate, String expectedDisburmentDate) {
1111+
final PostLoansRequest loanRequest = new PostLoansRequest() //
1112+
.loanTermFrequency(4).locale("en_GB").loanTermFrequencyType(2).numberOfRepayments(4).repaymentFrequencyType(2)
1113+
.interestRatePerPeriod(BigDecimal.valueOf(2)).repaymentEvery(1).principal(principal).amortizationType(1).interestType(1)
1114+
.interestCalculationPeriodType(0).dateFormat("dd MMMM yyyy").transactionProcessingStrategyCode(DEFAULT_STRATEGY)
1115+
.loanType("individual").submittedOnDate(submittedOnDate).expectedDisbursementDate(expectedDisburmentDate).clientId(clientId)
1116+
.productId(loanProductId);
1117+
return loanRequest;
1118+
}
1119+
10571120
private void enableLoanInterestRefundPstBusinessEvent(boolean enabled) {
10581121
externalEventHelper.configureBusinessEvent("LoanTransactionInterestRefundPostBusinessEvent", enabled);
10591122
}

0 commit comments

Comments
 (0)