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 static org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
19  
20  import org.kuali.ole.sys.OLEKeyConstants.CashReceipt;
21  import org.kuali.ole.sys.OLEPropertyConstants;
22  import org.kuali.ole.sys.document.AccountingDocument;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  /**
28   * Validation for the Cash Receipt family of documents which validates the sum amount of all
29   * accounting lines on the document.
30   */
31  public class CashReceiptFamilyAccountingLineTotalValidation extends GenericValidation {
32      private AccountingDocument accountingDocumentForValidation;
33  
34      /**
35       * Return true if source total is non-zero
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 isValid = true;
40  
41          if (getAccountingDocumentForValidation().getSourceTotal().isZero()) {
42              String errorProperty = DOCUMENT_ERROR_PREFIX + OLEPropertyConstants.SOURCE_ACCOUNTING_LINES;
43  
44              isValid = false;
45              GlobalVariables.getMessageMap().putError(errorProperty, CashReceipt.ERROR_ZERO_TOTAL, "Accounting Line Total");
46          }
47  
48          return isValid;
49      }
50  
51      /**
52       * Gets the accountingDocumentForValidation attribute. 
53       * @return Returns the accountingDocumentForValidation.
54       */
55      public AccountingDocument getAccountingDocumentForValidation() {
56          return accountingDocumentForValidation;
57      }
58  
59      /**
60       * Sets the accountingDocumentForValidation attribute value.
61       * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
62       */
63      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
64          this.accountingDocumentForValidation = accountingDocumentForValidation;
65      }
66  }