ifs-web-service/ifs-application-commons/src/main/java/org/innovateuk/ifs/application/forms/sections/yourprojectcosts/validator/YourProjectCostsFormValidator.java
/*
    This is a bit ugly but its validating that if there is a missmatch in the number of blank rows between assocaite dev and associate salary that we validate the form of the missmatching blank row
     */
This is a bit ugly but its validating that if there is a missmatch in the number of blank rows between assocaite dev and associate salary that we validate the form of the missmatching blank row
This is a bit ugly but its validating that if there is a missmatch in the number of blank rows between assocaite dev and associate salary that we validate the form of the missmatching blank row
private void validateSameNumberOfNonBlankAssociateRows(Map<String, AssociateDevelopmentCostRowForm> associateDevelopmentCostRows, Map<String, AssociateSalaryCostRowForm> associateSalaryCostRows, ValidationHandler validationHandler) {
        List<Map.Entry<String, AssociateDevelopmentCostRowForm>> blankDevRows = associateDevelopmentCostRows.entrySet().stream().filter(entry -> entry.getValue().isBlank()).collect(Collectors.toList());
        List<Map.Entry<String, AssociateSalaryCostRowForm>> blankSalRows = associateSalaryCostRows.entrySet().stream().filter(entry -> entry.getValue().isBlank()).collect(Collectors.toList());
        if (blankDevRows.size() == 1 && blankSalRows.size() == 0) {
            validateForm(blankDevRows.get(0).getValue(), validationHandler,"associateDevelopmentCostRows[%s].", blankDevRows.get(0).getKey());
        } else if (blankDevRows.size() == 0 && blankSalRows.size() == 1) {
            validateForm(blankSalRows.get(0).getValue(), validationHandler,"associateSalaryCostRows[%s].", blankSalRows.get(0).getKey());
        }
    }
private void validateSameNumberOfNonBlankAssociateRows ( Map < String , AssociateDevelopmentCostRowForm > associateDevelopmentCostRows , Map < String , AssociateSalaryCostRowForm > associateSalaryCostRows , ValidationHandler validationHandler ) { List < Map . Entry < String , AssociateDevelopmentCostRowForm > > blankDevRows = associateDevelopmentCostRows . entrySet ( ) . stream ( ) . filter ( entry -> entry . getValue ( ) . isBlank ( ) ) . collect ( Collectors . toList ( ) ) ; List < Map . Entry < String , AssociateSalaryCostRowForm > > blankSalRows = associateSalaryCostRows . entrySet ( ) . stream ( ) . filter ( entry -> entry . getValue ( ) . isBlank ( ) ) . collect ( Collectors . toList ( ) ) ; if ( blankDevRows . size ( ) == 1 && blankSalRows . size ( ) == 0 ) { validateForm ( blankDevRows . get ( 0 ) . getValue ( ) , validationHandler , "associateDevelopmentCostRows[%s]." , blankDevRows . get ( 0 ) . getKey ( ) ) ; } else if ( blankDevRows . size ( ) == 0 && blankSalRows . size ( ) == 1 ) { validateForm ( blankSalRows . get ( 0 ) . getValue ( ) , validationHandler , "associateSalaryCostRows[%s]." , blankSalRows . get ( 0 ) . getKey ( ) ) ; } }
This is a bit ugly but its validating that if there is a missmatch in the number of blank rows between assocaite dev and associate salary that we validate the form of the missmatching blank row
This is a bit ugly but its validating that if there is a missmatch in the number of blank rows between assocaite dev and associate salary that we validate the form of the missmatching blank row
// both having 1 blank row, or both having 0 blank rows is valid.