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.sys.document.validation.impl;
17  
18  import static org.kuali.ole.sys.OLEConstants.AMOUNT_PROPERTY_NAME;
19  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_INVALID_NEGATIVE_AMOUNT_NON_CORRECTION;
20  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_ZERO_AMOUNT;
21  
22  import org.kuali.ole.sys.businessobject.AccountingLine;
23  import org.kuali.ole.sys.document.AccountingDocument;
24  import org.kuali.ole.sys.document.validation.GenericValidation;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.rice.core.api.util.type.KualiDecimal;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  
29  /**
30   * Validates an accounting line that, if the line is not a correction document, the line amount is a positive amount
31   */
32  public class AccountingLineAmountPositiveValidation extends GenericValidation {
33      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountingLineAmountPositiveValidation.class);
34  
35      private AccountingDocument accountingDocumentForValidation;
36      private AccountingLine accountingLineForValidation;
37  
38      /**
39       * Check for zero amount, or negative on original (non-correction) document; no sign check for documents that are
40       * corrections to previous documents
41       * <strong>the accounting document must be the first parameter, the accounting line must be the second parameter</strong>
42       * @see org.kuali.ole.sys.document.validation.GenericValidation#validate(java.lang.Object[])
43       */
44      @Override
45      public boolean validate(AttributedDocumentEvent event) {
46          KualiDecimal amount = accountingLineForValidation.getAmount();
47          String correctsDocumentId = accountingDocumentForValidation.getFinancialSystemDocumentHeader().getFinancialDocumentInErrorNumber();
48  
49          if (amount != null) {
50              if (KualiDecimal.ZERO.compareTo(amount) == 0) { // amount == 0
51                  GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME, ERROR_ZERO_AMOUNT, "an accounting line");
52                  return false;
53              }
54              else {
55                  if (null == correctsDocumentId && KualiDecimal.ZERO.compareTo(amount) == 1) { // amount < 0
56                      GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME, ERROR_INVALID_NEGATIVE_AMOUNT_NON_CORRECTION);
57                      return false;
58                  }
59              }
60          }
61  
62          return true;
63      }
64  
65      /**
66       * Gets the accountingDocumentForValidation attribute.
67       * @return Returns the accountingDocumentForValidation.
68       */
69      public AccountingDocument getAccountingDocumentForValidation() {
70          return accountingDocumentForValidation;
71      }
72  
73      /**
74       * Sets the accountingDocumentForValidation attribute value.
75       * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
76       */
77      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
78          this.accountingDocumentForValidation = accountingDocumentForValidation;
79      }
80  
81      /**
82       * Gets the accountingLineForValidation attribute.
83       * @return Returns the accountingLineForValidation.
84       */
85      public AccountingLine getAccountingLineForValidation() {
86          return accountingLineForValidation;
87      }
88  
89      /**
90       * Sets the accountingLineForValidation attribute value.
91       * @param accountingLineForValidation The accountingLineForValidation to set.
92       */
93      public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
94          this.accountingLineForValidation = accountingLineForValidation;
95      }
96  }