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.AccountingDocument;
22  import org.kuali.ole.sys.document.service.DebitDeterminerService;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.core.api.util.type.KualiDecimal;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  /**
29   * Validation that checks the amounts on budget adjustment document accounting lines.
30   */
31  public class BudgetAdjustmentAccountingLineAmountValidation extends GenericValidation {
32      private BudgetAdjustmentAccountingLine accountingLineForValidation;
33      private AccountingDocument accountingDocumentForValidation;
34      private DebitDeterminerService debitDeterminerService;
35  
36      /**
37       * Validates the amounts on a budget adjustment accounting line, making sure that either the current adjustment amount or the base adjustment amount are not zero,
38       * and that all given amounts are positive.
39       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
40       */
41      public boolean validate(AttributedDocumentEvent event) {
42          boolean amountValid = true;
43  
44          // check amounts both current and base amounts are not zero
45          if (getAccountingLineForValidation().getCurrentBudgetAdjustmentAmount().isZero() && getAccountingLineForValidation().getBaseBudgetAdjustmentAmount().isZero()) {
46              GlobalVariables.getMessageMap().putError(OLEPropertyConstants.BASE_BUDGET_ADJUSTMENT_AMOUNT, OLEKeyConstants.ERROR_BA_AMOUNT_ZERO);
47              amountValid = false;
48          }
49  
50          // if not an error correction, all amounts must be positive
51          if (!debitDeterminerService.isErrorCorrection(getAccountingDocumentForValidation())) {
52              amountValid &= checkAmountSign(getAccountingLineForValidation().getCurrentBudgetAdjustmentAmount(), OLEPropertyConstants.CURRENT_BUDGET_ADJUSTMENT_AMOUNT, "Current");
53              amountValid &= checkAmountSign(getAccountingLineForValidation().getBaseBudgetAdjustmentAmount(), OLEPropertyConstants.BASE_BUDGET_ADJUSTMENT_AMOUNT, "Base");
54              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth1LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_1_LINE_AMOUNT, "Month 1");
55              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth2LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_2_LINE_AMOUNT, "Month 2");
56              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth3LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_3_LINE_AMOUNT, "Month 3");
57              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth4LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_4_LINE_AMOUNT, "Month 4");
58              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth5LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_5_LINE_AMOUNT, "Month 5");
59              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth6LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_6_LINE_AMOUNT, "Month 6");
60              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth7LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_7_LINE_AMOUNT, "Month 7");
61              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth8LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_8_LINE_AMOUNT, "Month 8");
62              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth8LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_9_LINE_AMOUNT, "Month 9");
63              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth10LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_10_LINE_AMOUNT, "Month 10");
64              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth10LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_11_LINE_AMOUNT, "Month 11");
65              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth12LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_12_LINE_AMOUNT, "Month 12");
66          }
67  
68          return amountValid;
69      }
70  
71      /**
72       * Helper method to check if an amount is negative and add an error if not.
73       * 
74       * @param amount to check
75       * @param propertyName to add error under
76       * @param label for error
77       * @return boolean indicating if the value has the requested sign
78       */
79      protected boolean checkAmountSign(KualiDecimal amount, String propertyName, String label) {
80          boolean correctSign = true;
81  
82          if (amount.isNegative()) {
83              GlobalVariables.getMessageMap().putError(propertyName, OLEKeyConstants.ERROR_BA_AMOUNT_NEGATIVE, label);
84              correctSign = false;
85          }
86  
87          return correctSign;
88      }
89  
90  
91      /**
92       * Gets the accountingLineForValidation attribute. 
93       * @return Returns the accountingLineForValidation.
94       */
95      public BudgetAdjustmentAccountingLine getAccountingLineForValidation() {
96          return accountingLineForValidation;
97      }
98  
99      /**
100      * Sets the accountingLineForValidation attribute value.
101      * @param accountingLineForValidation The accountingLineForValidation to set.
102      */
103     public void setAccountingLineForValidation(BudgetAdjustmentAccountingLine accountingLineForValidation) {
104         this.accountingLineForValidation = accountingLineForValidation;
105     }
106 
107     /**
108      * Gets the accountingDocumentForValidation attribute. 
109      * @return Returns the accountingDocumentForValidation.
110      */
111     public AccountingDocument getAccountingDocumentForValidation() {
112         return accountingDocumentForValidation;
113     }
114 
115     /**
116      * Sets the accountingDocumentForValidation attribute value.
117      * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
118      */
119     public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
120         this.accountingDocumentForValidation = accountingDocumentForValidation;
121     }
122 
123     /**
124      * Gets the debitDeterminerService attribute. 
125      * @return Returns the debitDeterminerService.
126      */
127     public DebitDeterminerService getDebitDeterminerService() {
128         return debitDeterminerService;
129     }
130 
131     /**
132      * Sets the debitDeterminerService attribute value.
133      * @param debitDeterminerService The debitDeterminerService to set.
134      */
135     public void setDebitDeterminerService(DebitDeterminerService debitDeterminerService) {
136         this.debitDeterminerService = debitDeterminerService;
137     }
138 }