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


##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/validator/WorkingCapitalLoanDelinquencyActionParseAndValidator.java:
##########
@@ -250,6 +252,24 @@ private void validateReschedule(final 
WorkingCapitalLoanDelinquencyAction action
         }
         if (hasFrequencyGroup) {
             validateFrequencyGroupProvided(action, dataValidator);
+            if (action.getFrequency() != null && action.getFrequency() > 0 && 
action.getFrequencyType() != null) {
+                validateFrequencyDoesNotEndBeforeBusinessDate(action, 
workingCapitalLoan, dataValidator);
+            }
+        }
+    }
+
+    /**
+     * Rejects a frequency change whose resulting period end date falls before 
the current business date. The candidate
+     * end date comes from the range schedule service, so it is the very date 
the re-date would persist.
+     */
+    private void validateFrequencyDoesNotEndBeforeBusinessDate(final 
WorkingCapitalLoanDelinquencyAction action,

Review Comment:
   Both validators now inject the write-side schedule service purely to call 
calculateRescheduledCurrentPeriodToDate, widening a mutation-oriented interface 
with a query method and creating a validator→service edge (no cycle today — 
both impls depend only on repositories — but a fragile direction in a module 
where the write service already depends on the validator).
   
   validateAndParse(command, loan, existing) already receives the full action 
list, and the validators already hold both repositories. So the same "one 
implementation" guarantee is available without the new interface method or the 
new dependency:
   
   
breachScheduleRepository.findCurrentOpenPeriodsOrderByPeriodNumberDesc(loanId, 
businessDate).stream().findFirst()
       .map(p -> 
WorkingCapitalLoanBreachScheduleEvaluationUtils.calculateRescheduledToDate(
               p.getFromDate(), action.getFrequency(), 
action.getFrequencyType(), existing))
   That also removes the redundant second findByWorkingCapitalLoanIdOrderById 
fetch — currently every reschedule request loads all breach actions twice 
(validator, then service).



-- 
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