oleksii-novikov-onix commented on code in PR #5740:
URL: https://github.com/apache/fineract/pull/5740#discussion_r3079102747


##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloanproduct/serialization/WorkingCapitalLoanProductDataValidator.java:
##########
@@ -442,12 +451,38 @@ private BigDecimal validateTermFields(final JsonElement 
element, final DataValid
         return principal;
     }
 
-    private void validateBreachField(final JsonElement element, final 
DataValidatorBuilder baseDataValidator) {
+    private Long validateBreachField(final JsonElement element, final 
DataValidatorBuilder baseDataValidator) {
+        Long breachId = null;
         if 
(this.fromApiJsonHelper.parameterExists(WorkingCapitalLoanProductConstants.breachIdParamName,
 element)) {
-            final Long breachId = 
this.fromApiJsonHelper.extractLongNamed(WorkingCapitalLoanProductConstants.breachIdParamName,
 element);
+            breachId = 
this.fromApiJsonHelper.extractLongNamed(WorkingCapitalLoanProductConstants.breachIdParamName,
 element);
             
baseDataValidator.reset().parameter(WorkingCapitalLoanProductConstants.breachIdParamName).value(breachId).ignoreIfNull()
                     .longGreaterThanZero();
         }
+        return breachId;
+    }
+
+    private void validateNearBreachField(final Long breachId, final 
JsonElement element, final DataValidatorBuilder baseDataValidator) {
+        if 
(this.fromApiJsonHelper.parameterExists(WorkingCapitalLoanProductConstants.nearBreachIdParamName,
 element)) {
+            final Long nearBreachId = 
this.fromApiJsonHelper.extractLongNamed(WorkingCapitalLoanProductConstants.nearBreachIdParamName,
+                    element);
+
+            if (breachId == null && nearBreachId != null) {
+                
baseDataValidator.reset().parameter(WorkingCapitalLoanProductConstants.nearBreachIdParamName)
+                        
.failWithCode("cannot.enable.nearch.breach.without.breach");
+                return;
+            }
+
+            if (nearBreachId != null) {
+                final WorkingCapitalBreachData breachData = 
workingCapitalBreachReadPlatformService.retrieveOne(breachId);
+                final WorkingCapitalNearBreachData nearBreachData = 
workingCapitalNearBreachReadPlatformService.retrieveOne(nearBreachId);
+                if 
(FrequencyTypeUtil.compareFrequencies(nearBreachData.getFrequency(), 
nearBreachData.getFrequencyType().getCode(),

Review Comment:
   Do we support partial updates? If yes, then we are losing this check, 
because at the beginning we check whether `nearBreachIdParamName` exists.  On a 
partial update that changes only breachId (to a breach with a shorter 
frequency), the existing nearBreach on the product is not re-validated.



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