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.OLEAccountingDocument;
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 OLEAccountingDocument 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          return amountValid;
68      }
69  
70      /**
71       * Helper method to check if an amount is negative and add an error if not.
72       * 
73       * @param amount to check
74       * @param propertyName to add error under
75       * @param label for error
76       * @return boolean indicating if the value has the requested sign
77       */
78      protected boolean checkAmountSign(KualiDecimal amount, String propertyName, String label) {
79          boolean correctSign = true;
80  
81          if (amount.isNegative()) {
82              GlobalVariables.getMessageMap().putError(propertyName, OLEKeyConstants.ERROR_BA_AMOUNT_NEGATIVE, label);
83              correctSign = false;
84          }
85  
86          return correctSign;
87      }
88  
89  
90      /**
91       * Gets the accountingLineForValidation attribute. 
92       * @return Returns the accountingLineForValidation.
93       */
94      public BudgetAdjustmentAccountingLine getAccountingLineForValidation() {
95          return accountingLineForValidation;
96      }
97  
98      /**
99       * Sets the accountingLineForValidation attribute value.
100      * @param accountingLineForValidation The accountingLineForValidation to set.
101      */
102     public void setAccountingLineForValidation(BudgetAdjustmentAccountingLine accountingLineForValidation) {
103         this.accountingLineForValidation = accountingLineForValidation;
104     }
105 
106     /**
107      * Gets the accountingDocumentForValidation attribute. 
108      * @return Returns the accountingDocumentForValidation.
109      */
110     public OLEAccountingDocument getAccountingDocumentForValidation() {
111         return accountingDocumentForValidation;
112     }
113 
114     /**
115      * Sets the accountingDocumentForValidation attribute value.
116      * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
117      */
118     public void setAccountingDocumentForValidation(OLEAccountingDocument accountingDocumentForValidation) {
119         this.accountingDocumentForValidation = accountingDocumentForValidation;
120     }
121 
122     /**
123      * Gets the debitDeterminerService attribute. 
124      * @return Returns the debitDeterminerService.
125      */
126     public DebitDeterminerService getDebitDeterminerService() {
127         return debitDeterminerService;
128     }
129 
130     /**
131      * Sets the debitDeterminerService attribute value.
132      * @param debitDeterminerService The debitDeterminerService to set.
133      */
134     public void setDebitDeterminerService(DebitDeterminerService debitDeterminerService) {
135         this.debitDeterminerService = debitDeterminerService;
136     }
137 }