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 a45ff9a3e FINERACT-1724  - fixes the JPA exception which is raised 
when a message was redelivered and earlier all the loans got closed for that 
given partition.
a45ff9a3e is described below

commit a45ff9a3e0ce5dc3e9641d9914f141f177ed0aa5
Author: Peter Bagrij <[email protected]>
AuthorDate: Fri Aug 11 14:50:45 2023 +0200

    FINERACT-1724
     - fixes the JPA exception which is raised when a message was redelivered 
and earlier all the loans got closed for that given partition.
---
 .../apache/fineract/cob/loan/LoanItemReader.java    |  9 ++++++---
 .../fineract/cob/loan/LoanItemReaderTest.java       | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java
 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java
index c236257f7..d94390f8b 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.LinkedBlockingQueue;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.fineract.cob.common.CustomJobParameterResolver;
 import org.apache.fineract.cob.data.LoanCOBParameter;
 import org.apache.fineract.cob.domain.LoanAccountLock;
@@ -33,6 +34,7 @@ import org.springframework.batch.core.StepExecution;
 import org.springframework.batch.core.annotation.BeforeStep;
 import org.springframework.batch.item.ExecutionContext;
 
+@Slf4j
 public class LoanItemReader extends AbstractLoanItemReader {
 
     private final RetrieveLoanIdService retrieveLoanIdService;
@@ -61,9 +63,10 @@ public class LoanItemReader extends AbstractLoanItemReader {
             loanIds = 
retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter,
                     
customJobParameterResolver.getCustomJobParameterById(stepExecution, 
LoanCOBConstant.IS_CATCH_UP_PARAMETER_NAME)
                             .map(Boolean::parseBoolean).orElse(false));
-
-            List<Long> lockedByCOBChunkProcessingAccountIds = 
getLoanIdsLockedWithChunkProcessingLock(loanIds);
-            loanIds.retainAll(lockedByCOBChunkProcessingAccountIds);
+            if (loanIds.size() > 0) {
+                List<Long> lockedByCOBChunkProcessingAccountIds = 
getLoanIdsLockedWithChunkProcessingLock(loanIds);
+                loanIds.retainAll(lockedByCOBChunkProcessingAccountIds);
+            }
         }
         setRemainingData(new LinkedBlockingQueue<>(loanIds));
     }
diff --git 
a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemReaderTest.java
 
b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemReaderTest.java
index 9fe36b1dc..2ebe0efbb 100644
--- 
a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemReaderTest.java
+++ 
b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemReaderTest.java
@@ -101,6 +101,27 @@ class LoanItemReaderTest {
         Mockito.verifyNoMoreInteractions(loanRepository);
     }
 
+    @Test
+    public void testLoanItemReadNoOpenLoansFound() throws Exception {
+        // given
+        ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, 
"test", "test", "UTC", null));
+        LoanItemReader loanItemReader = new LoanItemReader(loanRepository, 
retrieveLoanIdService, customJobParameterResolver,
+                loanLockingService);
+        when(stepExecution.getExecutionContext()).thenReturn(executionContext);
+        LoanCOBParameter loanCOBParameter = new LoanCOBParameter(1L, 5L);
+        
when(executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER)).thenReturn(loanCOBParameter);
+        
when(retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter,
 false))
+                .thenReturn(new ArrayList<>(List.of()));
+
+        // when + then
+        loanItemReader.beforeStep(stepExecution);
+        Loan myLoan = loanItemReader.read();
+        Assertions.assertNull(myLoan);
+
+        Mockito.verifyNoMoreInteractions(loanRepository);
+        Mockito.verifyNoInteractions(loanLockingService);
+    }
+
     @Test
     public void testLoanItemReaderMultiThreadRead() throws Exception {
         // given

Reply via email to