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.OLEConstants.ACCOUNTING_LINE_ERRORS;
19  import static org.kuali.ole.sys.OLEKeyConstants.AuxiliaryVoucher.ERROR_DIFFERENT_CHARTS;
20  
21  import java.util.List;
22  
23  import org.kuali.ole.sys.businessobject.AccountingLine;
24  import org.kuali.ole.sys.document.AccountingDocument;
25  import org.kuali.ole.sys.document.validation.GenericValidation;
26  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  
29  /**
30   * Validates that all accounting lines on the document use only one chart among them all.
31   */
32  public class AuxiliaryVoucherSingleChartUsedValidation extends GenericValidation {
33      private AccountingDocument accountingDocumentForValidation;
34  
35      /**
36       * Iterates <code>{@link AccountingLine}</code> instances in a given <code>{@link FinancialDocument}</code> instance and
37       * compares them to see if they are all in the same Chart.
38       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
39       */
40      public boolean validate(AttributedDocumentEvent event) {
41          boolean valid = true;
42  
43          String baseChartCode = null;
44          int index = 0;
45  
46          List<AccountingLine> lines = accountingDocumentForValidation.getSourceAccountingLines();
47          for (AccountingLine line : lines) {
48              if (index == 0) {
49                  baseChartCode = line.getChartOfAccountsCode();
50              }
51              else {
52                  String currentChartCode = line.getChartOfAccountsCode();
53                  if (!currentChartCode.equals(baseChartCode)) {
54                      GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DIFFERENT_CHARTS, new String[] {});
55                      return false;
56                  }
57              }
58              index++;
59          }
60          return true;
61      }
62  
63      /**
64       * Gets the accountingDocumentForValidation attribute. 
65       * @return Returns the accountingDocumentForValidation.
66       */
67      public AccountingDocument getAccountingDocumentForValidation() {
68          return accountingDocumentForValidation;
69      }
70  
71      /**
72       * Sets the accountingDocumentForValidation attribute value.
73       * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
74       */
75      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
76          this.accountingDocumentForValidation = accountingDocumentForValidation;
77      }
78  }