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.document.DisbursementVoucherDocument;
19  import org.kuali.ole.sys.OLEConstants;
20  import org.kuali.ole.sys.OLEKeyConstants;
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.core.api.util.type.KualiDecimal;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  import org.kuali.rice.krad.util.MessageMap;
28  
29  public class DisbursementVoucherDocumentAmountValidation extends GenericValidation {
30      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherDocumentAmountValidation.class);
31  
32      private AccountingDocument accountingDocumentForValidation;
33  
34      /**
35       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
36       */
37      public boolean validate(AttributedDocumentEvent event) {
38          LOG.debug("validate start");
39          
40          boolean isValid = true;
41          DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument) accountingDocumentForValidation;
42          
43          MessageMap errors = GlobalVariables.getMessageMap();
44          errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
45  
46          /* check total cannot be negative or zero */
47          if (!disbursementVoucherDocument.getDisbVchrCheckTotalAmount().isPositive()) {
48              errors.putError(OLEPropertyConstants.DISB_VCHR_CHECK_TOTAL_AMOUNT, OLEKeyConstants.ERROR_NEGATIVE_OR_ZERO_CHECK_TOTAL);
49              isValid = false;
50          }
51  
52          /* total accounting lines cannot be negative */
53          if (KualiDecimal.ZERO.compareTo(disbursementVoucherDocument.getSourceTotal()) == 1) {
54              errors.putErrorWithoutFullErrorPath(OLEConstants.ACCOUNTING_LINE_ERRORS, OLEKeyConstants.ERROR_NEGATIVE_ACCOUNTING_TOTAL);
55              isValid = false;
56          }
57  
58          /* total of accounting lines must match check total */
59          if (disbursementVoucherDocument.getDisbVchrCheckTotalAmount().compareTo(disbursementVoucherDocument.getSourceTotal()) != 0) {
60              errors.putErrorWithoutFullErrorPath(OLEConstants.ACCOUNTING_LINE_ERRORS, OLEKeyConstants.ERROR_CHECK_ACCOUNTING_TOTAL);
61              isValid = false;
62          }
63          
64          errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
65  
66          return isValid;
67      }
68  
69      /**
70       * Sets the accountingDocumentForValidation attribute value.
71       * 
72       * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
73       */
74      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
75          this.accountingDocumentForValidation = accountingDocumentForValidation;
76      }
77  
78      /**
79       * Gets the accountingDocumentForValidation attribute. 
80       * @return Returns the accountingDocumentForValidation.
81       */
82      public AccountingDocument getAccountingDocumentForValidation() {
83          return accountingDocumentForValidation;
84      }
85  
86  }