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 java.util.List;
19  
20  import org.kuali.ole.fp.businessobject.DisbursementVoucherNonResidentAlienTax;
21  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
22  import org.kuali.ole.fp.document.service.DisbursementVoucherTaxService;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.ole.sys.document.validation.impl.AccountingLineAmountPositiveValidation;
26  
27  public class DisbursementVoucherAccountingLineAmountPositiveValidation extends AccountingLineAmountPositiveValidation {
28      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherAccountingLineAmountPositiveValidation.class);
29  
30      /**
31       * @see org.kuali.ole.sys.document.validation.impl.AccountingLineAmountPositiveValidation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
32       */
33      @Override
34      public boolean validate(AttributedDocumentEvent event) {
35          LOG.debug("validate start");
36          boolean isValid = true;
37          
38          DisbursementVoucherDocument document = (DisbursementVoucherDocument) this.getAccountingDocumentForValidation();
39          DisbursementVoucherNonResidentAlienTax nonResidentAlienTax = document.getDvNonResidentAlienTax();
40  
41          // tax accounting lines can have negative amounts
42          if (nonResidentAlienTax != null) {
43              List<String> taxLineNumbers = SpringContext.getBean(DisbursementVoucherTaxService.class).getNRATaxLineNumbers(nonResidentAlienTax.getFinancialDocumentAccountingLineText());
44              
45              if (taxLineNumbers.contains(this.getAccountingLineForValidation().getSequenceNumber())) {
46                  return true;
47              }
48          }
49          
50          isValid = super.validate(event);
51  
52          return isValid;
53      }
54  }