This is an automated email from the ASF dual-hosted git repository.
arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new 4808bb348 FINERACT-1678: Fix Apply Penalty to overdue loan COB job
4808bb348 is described below
commit 4808bb3489c13f1f27f6a3fc5bd78fb59f0e3eb2
Author: Adam Saghy <[email protected]>
AuthorDate: Mon Aug 29 18:18:12 2022 +0200
FINERACT-1678: Fix Apply Penalty to overdue loan COB job
---
.../fineract/cob/COBBusinessStepServiceImpl.java | 11 ++-
.../fineract/cob/COBInputChannelInterceptor.java | 2 +
.../BusinessDateReadPlatformServiceImpl.java | 1 +
...ationWritePlatformServiceJpaRepositoryImpl.java | 3 -
.../service/LoanReadPlatformServiceImpl.java | 4 +-
.../integrationtests/SchedulerJobsTestResults.java | 78 ++++++++++++++++++++++
.../common/BusinessDateHelper.java | 52 +++++++++++++++
7 files changed, 144 insertions(+), 7 deletions(-)
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/cob/COBBusinessStepServiceImpl.java
b/fineract-provider/src/main/java/org/apache/fineract/cob/COBBusinessStepServiceImpl.java
index 03fdbf195..bce1fb4b0 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/cob/COBBusinessStepServiceImpl.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/cob/COBBusinessStepServiceImpl.java
@@ -26,6 +26,8 @@ import lombok.RequiredArgsConstructor;
import org.apache.fineract.cob.domain.BatchBusinessStep;
import org.apache.fineract.cob.domain.BatchBusinessStepRepository;
import
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
+import org.apache.fineract.infrastructure.core.domain.ActionContext;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.ApplicationContext;
@@ -42,8 +44,13 @@ public class COBBusinessStepServiceImpl implements
COBBusinessStepService {
@Override
public <T extends COBBusinessStep<S>, S extends AbstractPersistableCustom>
S run(TreeMap<Long, String> executionMap, S item) {
for (String businessStep : executionMap.values()) {
- COBBusinessStep<S> businessStepBean = (COBBusinessStep<S>)
applicationContext.getBean(businessStep);
- item = businessStepBean.execute(item);
+ try {
+ COBBusinessStep<S> businessStepBean = (COBBusinessStep<S>)
applicationContext.getBean(businessStep);
+ item = businessStepBean.execute(item);
+ } finally {
+ // Fallback to COB action context after each business step
+ ThreadLocalContextUtil.setActionContext(ActionContext.COB);
+ }
}
return item;
}
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/cob/COBInputChannelInterceptor.java
b/fineract-provider/src/main/java/org/apache/fineract/cob/COBInputChannelInterceptor.java
index 05626e77b..cb8e4b026 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/cob/COBInputChannelInterceptor.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/cob/COBInputChannelInterceptor.java
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.cob;
+import org.apache.fineract.infrastructure.core.domain.ActionContext;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
@@ -31,6 +32,7 @@ public class COBInputChannelInterceptor implements
ExecutorChannelInterceptor {
public Message<?> beforeHandle(Message<?> message, MessageChannel channel,
MessageHandler handler) {
COBMessage castedMessage = COBMessage.class.cast(message.getPayload());
ThreadLocalContextUtil.init(castedMessage.getContext());
+ ThreadLocalContextUtil.setActionContext(ActionContext.COB);
return new GenericMessage<>(castedMessage.getStepExecutionRequest());
}
}
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceImpl.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceImpl.java
index 62494a82a..9b7d2f2c8 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceImpl.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceImpl.java
@@ -73,6 +73,7 @@ public class BusinessDateReadPlatformServiceImpl implements
BusinessDateReadPlat
ZoneId zone = DateUtils.getDateTimeZoneOfTenant();
LocalDate tenantDate = LocalDate.now(zone);
businessDateMap.put(BusinessDateType.BUSINESS_DATE, tenantDate);
+ businessDateMap.put(BusinessDateType.COB_DATE, tenantDate);
if (configurationDomainService.isBusinessDateEnabled()) {
final List<BusinessDateData> businessDateDataList = this.findAll();
for (BusinessDateData businessDateData : businessDateDataList) {
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java
index dc825c079..7cc52f72e 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java
@@ -61,9 +61,6 @@ public class
GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements
@Transactional
@Override
public CommandProcessingResult update(final Long configId, final
JsonCommand command) {
-
- this.context.authenticatedUser();
-
try {
this.globalConfigurationDataValidator.validateForUpdate(command);
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
index 01f429879..11fb67d8d 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
@@ -1576,8 +1576,8 @@ public class LoanReadPlatformServiceImpl implements
LoanReadPlatformService {
continue;
}
- boolean isPenaltyDue =
installment.isOverdueOn(DateUtils.getBusinessLocalDate().plusDays(penaltyWaitPeriod
+ 1));
- boolean isDueToday =
installment.getDueDate().equals(DateUtils.getBusinessLocalDate().plusDays(penaltyWaitPeriod));
+ boolean isPenaltyDue =
installment.isOverdueOn(DateUtils.getBusinessLocalDate().minusDays(penaltyWaitPeriod).plusDays(1));
+ boolean isDueToday =
installment.getDueDate().equals(DateUtils.getBusinessLocalDate().minusDays(penaltyWaitPeriod));
if (isPenaltyDue) {
if (!backdatePenalties && !isDueToday) {
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java
index 52695379e..96d44fc25 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java
@@ -46,6 +46,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+import org.apache.fineract.integrationtests.common.BusinessDateHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
@@ -646,6 +648,82 @@ public class SchedulerJobsTestResults {
}
}
+ @Test
+ public void testLoanCOBApplyPenaltyOnDue() {
+ GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec,
responseSpec, Boolean.TRUE);
+ // set penalty wait period to 0
+
GlobalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec,
this.responseSpec, "10", "0");
+ this.loanTransactionHelper = new LoanTransactionHelper(requestSpec,
responseSpec);
+
+ final Integer clientID = ClientHelper.createClient(requestSpec,
responseSpec);
+ Assertions.assertNotNull(clientID);
+
+ Integer overdueFeeChargeId = ChargesHelper.createCharges(requestSpec,
responseSpec,
+
ChargesHelper.getLoanOverdueFeeJSONWithCalculationTypePercentage("1"));
+ Assertions.assertNotNull(overdueFeeChargeId);
+
+ final Integer loanProductID =
createLoanProduct(overdueFeeChargeId.toString());
+ Assertions.assertNotNull(loanProductID);
+ HashMap loanStatusHashMap;
+
+ final Integer loanID = applyForLoanApplication(clientID.toString(),
loanProductID.toString(), null, "10 January 2020");
+
+ Assertions.assertNotNull(loanID);
+
+ loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec,
responseSpec, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ loanStatusHashMap = this.loanTransactionHelper.approveLoan("01 March
2020", loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+
+ String loanDetails =
this.loanTransactionHelper.getLoanDetails(requestSpec, responseSpec, loanID);
+ loanStatusHashMap =
this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("02 March 2020",
loanID,
+
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+ BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec,
BusinessDateType.COB_DATE, LocalDate.of(2020, 4, 1));
+ String jobName = "Loan COB";
+
+ this.schedulerJobHelper.executeAndAwaitJob(jobName);
+ List<HashMap> repaymentScheduleDataAfter =
this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec,
loanID);
+ Assertions.assertEquals(0, (Integer)
repaymentScheduleDataAfter.get(1).get("penaltyChargesDue"),
+ "Verifying From Penalty Charges due fot first Repayment after
Successful completion of Scheduler Job");
+
+ BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec,
BusinessDateType.COB_DATE, LocalDate.of(2020, 4, 2));
+ this.schedulerJobHelper.executeAndAwaitJob(jobName);
+ repaymentScheduleDataAfter =
this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec,
loanID);
+ Assertions.assertEquals(39.39f, (Float)
repaymentScheduleDataAfter.get(1).get("penaltyChargesDue"),
+ "Verifying From Penalty Charges due fot first Repayment after
Successful completion of Scheduler Job");
+
+
GlobalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec,
this.responseSpec, "10", "1");
+
+ BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec,
BusinessDateType.COB_DATE, LocalDate.of(2020, 5, 2));
+ this.schedulerJobHelper.executeAndAwaitJob(jobName);
+ repaymentScheduleDataAfter =
this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec,
loanID);
+ Assertions.assertEquals(0, (Integer)
repaymentScheduleDataAfter.get(2).get("penaltyChargesDue"),
+ "Verifying From Penalty Charges due fot first Repayment after
Successful completion of Scheduler Job");
+
+ BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec,
BusinessDateType.COB_DATE, LocalDate.of(2020, 5, 3));
+ this.schedulerJobHelper.executeAndAwaitJob(jobName);
+ repaymentScheduleDataAfter =
this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec,
loanID);
+ Assertions.assertEquals(39.39f, (Float)
repaymentScheduleDataAfter.get(2).get("penaltyChargesDue"),
+ "Verifying From Penalty Charges due fot first Repayment after
Successful completion of Scheduler Job");
+
+ List<Map> transactions =
this.loanTransactionHelper.getLoanTransactions(this.requestSpec,
this.responseSpec, loanID);
+ Assertions.assertEquals(39.39f, (Float)
transactions.get(2).get("amount"));
+ Assertions.assertEquals(2020, ((List)
transactions.get(2).get("date")).get(0));
+ Assertions.assertEquals(4, ((List)
transactions.get(2).get("date")).get(1));
+ Assertions.assertEquals(2, ((List)
transactions.get(2).get("date")).get(2));
+
+ transactions =
this.loanTransactionHelper.getLoanTransactions(this.requestSpec,
this.responseSpec, loanID);
+ Assertions.assertEquals(39.39f, (Float)
transactions.get(3).get("amount"));
+ Assertions.assertEquals(2020, ((List)
transactions.get(3).get("date")).get(0));
+ Assertions.assertEquals(5, ((List)
transactions.get(3).get("date")).get(1));
+ Assertions.assertEquals(2, ((List)
transactions.get(3).get("date")).get(2));
+
+ GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec,
responseSpec, Boolean.FALSE);
+
GlobalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec,
this.responseSpec, "10", "2");
+ }
+
@Test
public void
testAvoidUnncessaryPenaltyWhenAmountZeroForOverdueLoansJobOutcome() throws
InterruptedException {
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec,
responseSpec);
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BusinessDateHelper.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BusinessDateHelper.java
new file mode 100644
index 000000000..d3a24790b
--- /dev/null
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BusinessDateHelper.java
@@ -0,0 +1,52 @@
+/**
+ * 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.integrationtests.common;
+
+import com.google.gson.Gson;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.time.LocalDate;
+import java.util.HashMap;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+
+@Slf4j
+public final class BusinessDateHelper {
+
+ private BusinessDateHelper() {}
+
+ public static HashMap updateBusinessDate(final RequestSpecification
requestSpec, final ResponseSpecification responseSpec,
+ final BusinessDateType type, final LocalDate date) {
+ final String BUSINESS_DATE_API =
"/fineract-provider/api/v1/businessdate?" + Utils.TENANT_IDENTIFIER;
+ log.info("------------------UPDATE BUSINESS
DATE----------------------");
+ log.info("------------------Type: {}, date: {}----------------------",
type, date);
+ return Utils.performServerPost(requestSpec, responseSpec,
BUSINESS_DATE_API, buildBusinessDateRequest(type, date), "changes");
+ }
+
+ private static String buildBusinessDateRequest(BusinessDateType type,
LocalDate date) {
+ final HashMap<String, String> map = new HashMap<>();
+ map.put("type", type.name());
+ map.put("date", Utils.dateFormatter.format(date));
+ map.put("dateFormat", Utils.DATE_FORMAT);
+ map.put("locale", "en");
+ log.info("map : {}", map);
+ return new Gson().toJson(map);
+ }
+
+}