@Override public boolean validate(AttributedDocumentEvent event) { boolean rulePassed = true; TravelDocument travelDocument = (TravelDocument) event.getDocument(); GlobalVariables.getMessageMap().addToErrorPath(KRADPropertyConstants.DOCUMENT); // Actual Expenses int counter = 0; for (ActualExpense actualExpense : travelDocument.getActualExpenses()) { String property = TemPropertyConstants.ACTUAL_EXPENSES + "[" + counter + "]"; /* * Determine if the detail is an amount that doesn't go over the threshold */ KualiDecimal total = actualExpense.getTotalDetailExpenseAmount(); if (!total.isZero()) { if (total.isGreaterThan(actualExpense.getExpenseAmount())) { GlobalVariables.getMessageMap() .putError( property + "." + TemPropertyConstants.EXPENSE_AMOUNT, TemKeyConstants.ERROR_TEM_DETAIL_GREATER_THAN_EXPENSE); rulePassed = false; } else if (total.isLessThan(actualExpense.getExpenseAmount())) { GlobalVariables.getMessageMap() .putError( property + "." + TemPropertyConstants.EXPENSE_AMOUNT, TemKeyConstants.ERROR_TEM_DETAIL_LESS_THAN_EXPENSE); rulePassed = false; } } counter++; } // Imported Expenses counter = 0; for (ImportedExpense importedExpense : travelDocument.getImportedExpenses()) { String property = TemPropertyConstants.IMPORTED_EXPENSES + "[" + counter + "]"; // Determine if the detail is an amount that doesn't go over the threshold KualiDecimal total = KualiDecimal.ZERO; for (TemExpense detail : importedExpense.getExpenseDetails()) { total = total.add(detail.getExpenseAmount()); } if (!total.isZero()) { if (total.isGreaterThan(importedExpense.getExpenseAmount())) { GlobalVariables.getMessageMap() .putError( property + "." + TemPropertyConstants.EXPENSE_AMOUNT, TemKeyConstants.ERROR_TEM_DETAIL_GREATER_THAN_EXPENSE); rulePassed = false; } else if (total.isLessThan(importedExpense.getExpenseAmount())) { GlobalVariables.getMessageMap() .putError( property + "." + TemPropertyConstants.EXPENSE_AMOUNT, TemKeyConstants.ERROR_TEM_DETAIL_LESS_THAN_EXPENSE); rulePassed = false; } } counter++; } GlobalVariables.getMessageMap().clearErrorPath(); return rulePassed; }