adamsaghy commented on code in PR #3114:
URL: https://github.com/apache/fineract/pull/3114#discussion_r1164559989


##########
fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBPartitioner.java:
##########
@@ -66,34 +69,24 @@ private Map<String, ExecutionContext> getPartitions(int 
partitionSize, Set<Busin
             stopJobExecution();
             return Map.of();
         }
-        int partitionIndex = 1;
-        createNewPartition(partitions, partitionIndex, cobBusinessSteps);
         if (!Objects.isNull(minAndMaxLoanId)) {
-            long remainingLoanIdCount = minAndMaxLoanId.getMaxLoanId() - 
minAndMaxLoanId.getMinLoanId() + 1;
-            long startLoanId = minAndMaxLoanId.getMinLoanId();
-            long endLoanId;
-            do {
-                String key = PARTITION_PREFIX + partitionIndex;
-                ExecutionContext executionContext = partitions.get(key);
-                if (remainingLoanIdCount > partitionSize) {
-                    endLoanId = startLoanId + partitionSize - 1;
-                    partitionIndex++;
-                    createNewPartition(partitions, partitionIndex, 
cobBusinessSteps);
-                } else {
-                    endLoanId = minAndMaxLoanId.getMaxLoanId();
-                }
-                executionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, new 
LoanCOBParameter(startLoanId, endLoanId));
-                startLoanId = startLoanId + partitionSize;
-                remainingLoanIdCount = minAndMaxLoanId.getMaxLoanId() - 
endLoanId;
-            } while (remainingLoanIdCount > 0);
+            List<Long> loanIdsInRange = 
LongStream.rangeClosed(minAndMaxLoanId.getMinLoanId(), 
minAndMaxLoanId.getMaxLoanId()).boxed()
+                    .toList();
+            List<List<Long>> loanIdPartitions = 
Lists.partition(loanIdsInRange, partitionSize);
+            for (int i = 0; i < loanIdPartitions.size(); i++) {
+                createNewPartition(partitions, i + 1, cobBusinessSteps, 
loanIdPartitions.get(i));
+            }
+        } else {
+            createNewPartition(partitions, 1, cobBusinessSteps, List.of(0L));
         }
         return partitions;
     }
 
     private void createNewPartition(Map<String, ExecutionContext> partitions, 
int partitionIndex,
-            Set<BusinessStepNameAndOrder> cobBusinessSteps) {
+            Set<BusinessStepNameAndOrder> cobBusinessSteps, List<Long> 
loanIds) {
         ExecutionContext executionContext = new ExecutionContext();
         executionContext.put(LoanCOBConstant.BUSINESS_STEPS, cobBusinessSteps);
+        executionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, new 
LoanCOBParameter(loanIds.get(0), loanIds.get(loanIds.size() - 1)));

Review Comment:
   why -1 day?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to