You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "b0c1 (via GitHub)" <gi...@apache.org> on 2023/04/19 07:09:12 UTC

[GitHub] [fineract] b0c1 opened a new pull request, #3132: FINERACT-1724 - Loan CatchUp fix

b0c1 opened a new pull request, #3132:
URL: https://github.com/apache/fineract/pull/3132

   FINERACT-1724 - Loan CatchUp fix
   - [x] Update null loan cob date when hard lock
   - [x] Update hard lock to soft lock
   - [x] Ignore null loan cob date when catch up
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] adamsaghy commented on a diff in pull request #3132: FINERACT-1724 - Loan CatchUp fix

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3132:
URL: https://github.com/apache/fineract/pull/3132#discussion_r1170998041


##########
fineract-provider/src/main/java/org/apache/fineract/cob/service/AsyncLoanCOBExecutorServiceImpl.java:
##########
@@ -47,26 +46,31 @@
 import org.springframework.batch.core.repository.JobRestartException;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 @Service
 @RequiredArgsConstructor
 public class AsyncLoanCOBExecutorServiceImpl implements AsyncLoanCOBExecutorService {
 
-    private final LoanRepository loanRepository;
     private final JobLocator jobLocator;
     private final ScheduledJobDetailRepository scheduledJobDetailRepository;
     private final JobStarter jobStarter;
     private final JobParameterRepository jobParameterRepository;
     private final RetrieveLoanIdService retrieveLoanIdService;
+    private final LoanAccountLockService accountLockService;
 
     @Override
     @Async("loanCOBCatchUpThreadPoolTaskExecutor")
+    @Transactional(propagation = Propagation.REQUIRED)

Review Comment:
   Is this required?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] b0c1 commented on a diff in pull request #3132: FINERACT-1724 - Loan CatchUp fix

Posted by "b0c1 (via GitHub)" <gi...@apache.org>.
b0c1 commented on code in PR #3132:
URL: https://github.com/apache/fineract/pull/3132#discussion_r1171005297


##########
fineract-provider/src/main/java/org/apache/fineract/cob/service/AsyncLoanCOBExecutorServiceImpl.java:
##########
@@ -47,26 +46,31 @@
 import org.springframework.batch.core.repository.JobRestartException;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 @Service
 @RequiredArgsConstructor
 public class AsyncLoanCOBExecutorServiceImpl implements AsyncLoanCOBExecutorService {
 
-    private final LoanRepository loanRepository;
     private final JobLocator jobLocator;
     private final ScheduledJobDetailRepository scheduledJobDetailRepository;
     private final JobStarter jobStarter;
     private final JobParameterRepository jobParameterRepository;
     private final RetrieveLoanIdService retrieveLoanIdService;
+    private final LoanAccountLockService accountLockService;
 
     @Override
     @Async("loanCOBCatchUpThreadPoolTaskExecutor")
+    @Transactional(propagation = Propagation.REQUIRED)

Review Comment:
   It was before we re-think how it will be working... now it's removed, thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] adamsaghy commented on a diff in pull request #3132: FINERACT-1724 - Loan CatchUp fix

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3132:
URL: https://github.com/apache/fineract/pull/3132#discussion_r1175271651


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCatchUpIntegrationTest.java:
##########
@@ -0,0 +1,193 @@
+/**
+ * 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;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.path.json.JsonPath;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.fineract.batch.domain.BatchRequest;
+import org.apache.fineract.batch.domain.BatchResponse;
+import org.apache.fineract.client.models.GetLoansLoanIdResponse;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+import org.apache.fineract.integrationtests.common.BatchHelper;
+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;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
+import org.apache.fineract.integrationtests.common.loans.LoanAccountLockHelper;
+import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanCOBCatchUpHelper;
+import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
+import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
+import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
+import org.apache.fineract.integrationtests.useradministration.users.UserHelper;
+import org.apache.http.HttpStatus;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(LoanTestLifecycleExtension.class)
+public class LoanCatchUpIntegrationTest {
+
+    private static final String REPAYMENT_LOAN_PERMISSION = "REPAYMENT_LOAN";
+    private static final String READ_LOAN_PERMISSION = "READ_LOAN";
+
+    private ResponseSpecification responseSpec;
+    private RequestSpecification requestSpec;
+    private LoanCOBCatchUpHelper loanCOBCatchUpHelper;
+    private LoanTransactionHelper loanTransactionHelper;
+    private LoanAccountLockHelper loanAccountLockHelper;
+
+    @BeforeEach
+    public void setup() {
+        Utils.initializeRESTAssured();
+        loanCOBCatchUpHelper = new LoanCOBCatchUpHelper();
+        requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+        requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+        requestSpec.header("Fineract-Platform-TenantId", "default");
+        responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+        this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+    }
+
+    @Test
+    public void testCatchUpInLockedInstance() {
+        try {
+            GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
+            BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, LocalDate.of(2020, 3, 2));
+            GlobalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec, "10", "0");
+            loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
+            loanAccountLockHelper = new LoanAccountLockHelper(requestSpec, new ResponseSpecBuilder().expectStatusCode(202).build());
+
+            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 = loanTransactionHelper.approveLoan("01 March 2020", loanID);
+            LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+
+            String loanDetails = loanTransactionHelper.getLoanDetails(requestSpec, responseSpec, loanID);
+            loanStatusHashMap = 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, 3, 2));
+            loanAccountLockHelper.placeSoftLockOnLoanAccount(loanID, "LOAN_INLINE_COB_PROCESSING", "Sample error");
+
+            BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, LocalDate.of(2020, 3, 10));
+
+            loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
+            loanCOBCatchUpHelper.executeLoanCOBCatchUp();

Review Comment:
   Would be nicer to check whether the job finished with the execution.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] adamsaghy commented on a diff in pull request #3132: FINERACT-1724 - Loan CatchUp fix

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3132:
URL: https://github.com/apache/fineract/pull/3132#discussion_r1170988256


##########
fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLockRepository.java:
##########
@@ -32,4 +35,26 @@ public interface LoanAccountLockRepository extends JpaRepository<LoanAccountLock
     List<LoanAccountLock> findAllByLoanIdIn(List<Long> loanIds);
 
     boolean existsByLoanIdAndLockOwner(Long loanId, LockOwner lockOwner);
+
+    @Query(value = """
+                                                 update m_loan as loan set loan.last_closed_business_date = (select lck.lock_placed_on_cob_business_date - 1
+                                                 from m_loan_account_locks lck
+                                                 where lck.loan_id = loan.id
+                                                   and lck.lock_placed_on_cob_business_date is not null
+                                                   and lck.error is not null
+                                                   and lck.lock_owner in (:lockOwners))
+            where loan.last_closed_business_date is null and exists  (select lck.loan_id
+                          from m_loan_account_locks lck  where lck.loan_id = loan.id
+                            and lck.lock_placed_on_cob_business_date is not null and lck.error is not null
+                            and lck.lock_owner in (:lockOwners))""", nativeQuery = true)
+    @Modifying(flushAutomatically = true)
+    void updateLoanFromAccountLocks(@Param("lockOwners") List<String> lockOwners);
+
+    @Query("""
+            update LoanAccountLock lck set

Review Comment:
   I reckon this should work for inline cob hard lock as well (LOAN_INLINE_COB_PROCESSING)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] taskain7 merged pull request #3132: FINERACT-1724 - Loan CatchUp fix

Posted by "taskain7 (via GitHub)" <gi...@apache.org>.
taskain7 merged PR #3132:
URL: https://github.com/apache/fineract/pull/3132


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] b0c1 commented on a diff in pull request #3132: FINERACT-1724 - Loan CatchUp fix

Posted by "b0c1 (via GitHub)" <gi...@apache.org>.
b0c1 commented on code in PR #3132:
URL: https://github.com/apache/fineract/pull/3132#discussion_r1171003660


##########
fineract-provider/src/main/java/org/apache/fineract/cob/api/InternalLoanAccountLockApiResource.java:
##########
@@ -76,4 +77,23 @@ public Response placeLockOnLoanAccount(@Context final UriInfo uriInfo, @PathPara
         loanAccountLockRepository.save(loanAccountLock);
         return Response.status(Response.Status.ACCEPTED).build();
     }
+
+    @POST

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] adamsaghy commented on a diff in pull request #3132: FINERACT-1724 - Loan CatchUp fix

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3132:
URL: https://github.com/apache/fineract/pull/3132#discussion_r1170988256


##########
fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLockRepository.java:
##########
@@ -32,4 +35,26 @@ public interface LoanAccountLockRepository extends JpaRepository<LoanAccountLock
     List<LoanAccountLock> findAllByLoanIdIn(List<Long> loanIds);
 
     boolean existsByLoanIdAndLockOwner(Long loanId, LockOwner lockOwner);
+
+    @Query(value = """
+                                                 update m_loan as loan set loan.last_closed_business_date = (select lck.lock_placed_on_cob_business_date - 1
+                                                 from m_loan_account_locks lck
+                                                 where lck.loan_id = loan.id
+                                                   and lck.lock_placed_on_cob_business_date is not null
+                                                   and lck.error is not null
+                                                   and lck.lock_owner in (:lockOwners))
+            where loan.last_closed_business_date is null and exists  (select lck.loan_id
+                          from m_loan_account_locks lck  where lck.loan_id = loan.id
+                            and lck.lock_placed_on_cob_business_date is not null and lck.error is not null
+                            and lck.lock_owner in (:lockOwners))""", nativeQuery = true)
+    @Modifying(flushAutomatically = true)
+    void updateLoanFromAccountLocks(@Param("lockOwners") List<String> lockOwners);
+
+    @Query("""
+            update LoanAccountLock lck set

Review Comment:
   I reckon this should work for inline cob hard lock as well (LOAN_INLINE_COB_PROCESSING)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] adamsaghy commented on a diff in pull request #3132: FINERACT-1724 - Loan CatchUp fix

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3132:
URL: https://github.com/apache/fineract/pull/3132#discussion_r1170985763


##########
fineract-provider/src/main/java/org/apache/fineract/cob/api/InternalLoanAccountLockApiResource.java:
##########
@@ -76,4 +77,23 @@ public Response placeLockOnLoanAccount(@Context final UriInfo uriInfo, @PathPara
         loanAccountLockRepository.save(loanAccountLock);
         return Response.status(Response.Status.ACCEPTED).build();
     }
+
+    @POST

Review Comment:
   Please update with optionally provide error the existing `placeLockOnLoanAccount` instead of creating a new one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org