From 5f9845f86a4d8cbf3a374c8a525b9856b15bcbf7 Mon Sep 17 00:00:00 2001 From: Arnold Galovics Date: Sun, 3 Mar 2024 19:17:16 +0100 Subject: [PATCH] FINERACT-1971: Triggering a loan level event during reamortization and reaging --- .../loan/reaging/LoanReAgeBusinessEvent.java | 36 ++++++++++++++ .../reaging/LoanUndoReAgeBusinessEvent.java | 36 ++++++++++++++ .../LoanReAmortizeBusinessEvent.java | 36 ++++++++++++++ .../LoanUndoReAmortizeBusinessEvent.java | 36 ++++++++++++++ .../reaging/LoanReAgingServiceImpl.java | 4 ++ .../LoanReAmortizationServiceImpl.java | 4 ++ .../db/changelog/tenant/changelog-tenant.xml | 1 + ...vent_for_loan_reaging_reamortization_2.xml | 49 +++++++++++++++++++ ...entConfigurationValidationServiceTest.java | 6 ++- .../ExternalEventConfigurationHelper.java | 20 ++++++++ 10 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reaging/LoanReAgeBusinessEvent.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reaging/LoanUndoReAgeBusinessEvent.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reamortization/LoanReAmortizeBusinessEvent.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reamortization/LoanUndoReAmortizeBusinessEvent.java create mode 100644 fineract-provider/src/main/resources/db/changelog/tenant/parts/0138_add_external_event_for_loan_reaging_reamortization_2.xml diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reaging/LoanReAgeBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reaging/LoanReAgeBusinessEvent.java new file mode 100644 index 00000000000..1dfea126dcc --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reaging/LoanReAgeBusinessEvent.java @@ -0,0 +1,36 @@ +/** + * 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.reaging; + +import org.apache.fineract.infrastructure.event.business.domain.loan.LoanBusinessEvent; +import org.apache.fineract.portfolio.loanaccount.domain.Loan; + +public class LoanReAgeBusinessEvent extends LoanBusinessEvent { + + private static final String TYPE = "LoanReAgeBusinessEvent"; + + public LoanReAgeBusinessEvent(Loan value) { + super(value); + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reaging/LoanUndoReAgeBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reaging/LoanUndoReAgeBusinessEvent.java new file mode 100644 index 00000000000..12830c2c5f0 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reaging/LoanUndoReAgeBusinessEvent.java @@ -0,0 +1,36 @@ +/** + * 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.reaging; + +import org.apache.fineract.infrastructure.event.business.domain.loan.LoanBusinessEvent; +import org.apache.fineract.portfolio.loanaccount.domain.Loan; + +public class LoanUndoReAgeBusinessEvent extends LoanBusinessEvent { + + private static final String TYPE = "LoanUndoReAgeBusinessEvent"; + + public LoanUndoReAgeBusinessEvent(Loan value) { + super(value); + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reamortization/LoanReAmortizeBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reamortization/LoanReAmortizeBusinessEvent.java new file mode 100644 index 00000000000..ba3dce4a081 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reamortization/LoanReAmortizeBusinessEvent.java @@ -0,0 +1,36 @@ +/** + * 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.reamortization; + +import org.apache.fineract.infrastructure.event.business.domain.loan.LoanBusinessEvent; +import org.apache.fineract.portfolio.loanaccount.domain.Loan; + +public class LoanReAmortizeBusinessEvent extends LoanBusinessEvent { + + private static final String TYPE = "LoanReAmortizeBusinessEvent"; + + public LoanReAmortizeBusinessEvent(Loan value) { + super(value); + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reamortization/LoanUndoReAmortizeBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reamortization/LoanUndoReAmortizeBusinessEvent.java new file mode 100644 index 00000000000..58e4b8cf470 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/reamortization/LoanUndoReAmortizeBusinessEvent.java @@ -0,0 +1,36 @@ +/** + * 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.reamortization; + +import org.apache.fineract.infrastructure.event.business.domain.loan.LoanBusinessEvent; +import org.apache.fineract.portfolio.loanaccount.domain.Loan; + +public class LoanUndoReAmortizeBusinessEvent extends LoanBusinessEvent { + + private static final String TYPE = "LoanUndoReAmortizeBusinessEvent"; + + public LoanUndoReAmortizeBusinessEvent(Loan value) { + super(value); + } + + @Override + public String getType() { + return TYPE; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java index f08350527e2..39bf599cd43 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java @@ -32,6 +32,8 @@ import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ExternalIdFactory; +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.reaging.LoanReAgeTransactionBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reaging.LoanUndoReAgeTransactionBusinessEvent; import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; @@ -76,6 +78,7 @@ public CommandProcessingResult reAge(Long loanId, JsonCommand command) { reAgingParameterRepository.saveAndFlush(reAgeParameter); // 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)); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // @@ -113,6 +116,7 @@ public CommandProcessingResult undoReAge(Long loanId, JsonCommand command) { loanTransactionRepository.saveAndFlush(reAgeTransaction); // delinquency recalculation will be triggered by the event in a decoupled way via a listener + businessEventNotifierService.notifyPostBusinessEvent(new LoanUndoReAgeBusinessEvent(loan)); businessEventNotifierService.notifyPostBusinessEvent(new LoanUndoReAgeTransactionBusinessEvent(reAgeTransaction)); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reamortization/LoanReAmortizationServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reamortization/LoanReAmortizationServiceImpl.java index 4909adbb1f3..c3ff06eb691 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reamortization/LoanReAmortizationServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reamortization/LoanReAmortizationServiceImpl.java @@ -32,6 +32,8 @@ import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ExternalIdFactory; +import org.apache.fineract.infrastructure.event.business.domain.loan.reamortization.LoanReAmortizeBusinessEvent; +import org.apache.fineract.infrastructure.event.business.domain.loan.reamortization.LoanUndoReAmortizeBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reamortization.LoanReAmortizeTransactionBusinessEvent; import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reamortization.LoanUndoReAmortizeTransactionBusinessEvent; import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; @@ -68,6 +70,7 @@ public CommandProcessingResult reAmortize(Long loanId, JsonCommand command) { loanTransactionRepository.saveAndFlush(reAmortizeTransaction); // delinquency recalculation will be triggered by the event in a decoupled way via a listener + businessEventNotifierService.notifyPostBusinessEvent(new LoanReAmortizeBusinessEvent(loan)); businessEventNotifierService.notifyPostBusinessEvent(new LoanReAmortizeTransactionBusinessEvent(reAmortizeTransaction)); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // @@ -96,6 +99,7 @@ public CommandProcessingResult undoReAmortize(Long loanId, JsonCommand command) loanTransactionRepository.saveAndFlush(reAmortizeTransaction); // delinquency recalculation will be triggered by the event in a decoupled way via a listener + businessEventNotifierService.notifyPostBusinessEvent(new LoanUndoReAmortizeBusinessEvent(loan)); businessEventNotifierService.notifyPostBusinessEvent(new LoanUndoReAmortizeTransactionBusinessEvent(reAmortizeTransaction)); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml index 5b640f42d03..9869549149c 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml @@ -157,4 +157,5 @@ + diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0138_add_external_event_for_loan_reaging_reamortization_2.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0138_add_external_event_for_loan_reaging_reamortization_2.xml new file mode 100644 index 00000000000..a0950ee3546 --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0138_add_external_event_for_loan_reaging_reamortization_2.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java index 8c30bdad3cc..2e25f354fc0 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java @@ -100,7 +100,8 @@ public void givenAllConfigurationWhenValidatedThenValidationSuccessful() throws "LoanTransactionDownPaymentPostBusinessEvent", "LoanTransactionDownPaymentPreBusinessEvent", "LoanAccountDelinquencyPauseChangedBusinessEvent", "LoanAccountCustomSnapshotBusinessEvent", "LoanReAgeTransactionBusinessEvent", "LoanUndoReAgeTransactionBusinessEvent", "LoanReAmortizeTransactionBusinessEvent", - "LoanUndoReAmortizeTransactionBusinessEvent"); + "LoanUndoReAmortizeTransactionBusinessEvent", "LoanReAgeBusinessEvent", "LoanUndoReAgeBusinessEvent", + "LoanReAmortizeBusinessEvent", "LoanUndoReAmortizeBusinessEvent"); List tenants = Arrays .asList(new FineractPlatformTenant(1L, "default", "Default Tenant", "Europe/Budapest", null)); @@ -182,7 +183,8 @@ public void givenMissingEventConfigurationWhenValidatedThenThrowException() thro "LoanTransactionDownPaymentPostBusinessEvent", "LoanTransactionDownPaymentPreBusinessEvent", "LoanAccountDelinquencyPauseChangedBusinessEvent", "LoanAccountCustomSnapshotBusinessEvent", "LoanReAgeTransactionBusinessEvent", "LoanUndoReAgeTransactionBusinessEvent", "LoanReAmortizeTransactionBusinessEvent", - "LoanUndoReAmortizeTransactionBusinessEvent"); + "LoanUndoReAmortizeTransactionBusinessEvent", "LoanReAgeBusinessEvent", "LoanUndoReAgeBusinessEvent", + "LoanReAmortizeBusinessEvent", "LoanUndoReAmortizeBusinessEvent"); List tenants = Arrays .asList(new FineractPlatformTenant(1L, "default", "Default Tenant", "Europe/Budapest", null)); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java index 1196b72db47..434a2b8d5a5 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java @@ -520,6 +520,26 @@ public static ArrayList> getDefaultExternalEventConfiguratio loanUndoReAmortizeTransactionBusinessEvent.put("enabled", false); defaults.add(loanUndoReAmortizeTransactionBusinessEvent); + Map loanReAgeBusinessEvent = new HashMap<>(); + loanReAgeBusinessEvent.put("type", "LoanReAgeBusinessEvent"); + loanReAgeBusinessEvent.put("enabled", false); + defaults.add(loanReAgeBusinessEvent); + + Map loanUndoReAgeBusinessEvent = new HashMap<>(); + loanUndoReAgeBusinessEvent.put("type", "LoanUndoReAgeBusinessEvent"); + loanUndoReAgeBusinessEvent.put("enabled", false); + defaults.add(loanUndoReAgeBusinessEvent); + + Map loanReAmortizeBusinessEvent = new HashMap<>(); + loanReAmortizeBusinessEvent.put("type", "LoanReAmortizeBusinessEvent"); + loanReAmortizeBusinessEvent.put("enabled", false); + defaults.add(loanReAmortizeBusinessEvent); + + Map loanUndoReAmortizeBusinessEvent = new HashMap<>(); + loanUndoReAmortizeBusinessEvent.put("type", "LoanUndoReAmortizeBusinessEvent"); + loanUndoReAmortizeBusinessEvent.put("enabled", false); + defaults.add(loanUndoReAmortizeBusinessEvent); + return defaults; }