View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.validation.impl;
17  
18  import org.kuali.ole.fp.businessobject.BudgetAdjustmentAccountingLine;
19  import org.kuali.ole.sys.OLEKeyConstants;
20  import org.kuali.ole.sys.OLEPropertyConstants;
21  import org.kuali.ole.sys.document.validation.GenericValidation;
22  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
23  import org.kuali.rice.core.api.util.type.KualiDecimal;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  
26  /**
27   * Validation for a budget adjustment accounting line that validates the information in the monthly lines
28   */
29  public class BudgetAdjustmentAccountingLineMonthlyLinesValidation extends GenericValidation {
30      private BudgetAdjustmentAccountingLine accountingLineForValidation;
31  
32      /**
33       * Validates the total of the monthly amount fields (if not 0) equals the current budget amount. If current budget is 0, then
34       * total of monthly fields must be 0.
35       * 
36       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
37       */
38      public boolean validate(AttributedDocumentEvent event) {
39          boolean validMonthlyLines = true;
40  
41          KualiDecimal monthlyTotal = getAccountingLineForValidation().getMonthlyLinesTotal();
42          if (monthlyTotal.isNonZero() && monthlyTotal.compareTo(getAccountingLineForValidation().getCurrentBudgetAdjustmentAmount()) != 0) {
43              GlobalVariables.getMessageMap().putError(OLEPropertyConstants.CURRENT_BUDGET_ADJUSTMENT_AMOUNT, OLEKeyConstants.ERROR_DOCUMENT_BA_MONTH_TOTAL_NOT_EQUAL_CURRENT);
44              validMonthlyLines = false;
45          }
46  
47          return validMonthlyLines;
48      }
49  
50      /**
51       * Gets the accountingLineForValidation attribute. 
52       * @return Returns the accountingLineForValidation.
53       */
54      public BudgetAdjustmentAccountingLine getAccountingLineForValidation() {
55          return accountingLineForValidation;
56      }
57  
58      /**
59       * Sets the accountingLineForValidation attribute value.
60       * @param accountingLineForValidation The accountingLineForValidation to set.
61       */
62      public void setAccountingLineForValidation(BudgetAdjustmentAccountingLine accountingLineForValidation) {
63          this.accountingLineForValidation = accountingLineForValidation;
64      }
65  }