1 /*
2 * The Kuali Financial System, a comprehensive financial management system for higher education.
3 *
4 * Copyright 2005-2014 The Kuali Foundation
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package org.kuali.kfs.fp.document.validation.impl;
20
21 import static org.kuali.kfs.sys.KFSConstants.ACCOUNTING_LINE_ERRORS;
22 import static org.kuali.kfs.sys.KFSKeyConstants.AuxiliaryVoucher.ERROR_DIFFERENT_CHARTS;
23
24 import java.util.List;
25
26 import org.kuali.kfs.sys.businessobject.AccountingLine;
27 import org.kuali.kfs.sys.document.AccountingDocument;
28 import org.kuali.kfs.sys.document.validation.GenericValidation;
29 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
30 import org.kuali.rice.krad.util.GlobalVariables;
31
32 /**
33 * Validates that all accounting lines on the document use only one chart among them all.
34 */
35 public class AuxiliaryVoucherSingleChartUsedValidation extends GenericValidation {
36 private AccountingDocument accountingDocumentForValidation;
37
38 /**
39 * Iterates <code>{@link AccountingLine}</code> instances in a given <code>{@link FinancialDocument}</code> instance and
40 * compares them to see if they are all in the same Chart.
41 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
42 */
43 public boolean validate(AttributedDocumentEvent event) {
44 boolean valid = true;
45
46 String baseChartCode = null;
47 int index = 0;
48
49 List<AccountingLine> lines = accountingDocumentForValidation.getSourceAccountingLines();
50 for (AccountingLine line : lines) {
51 if (index == 0) {
52 baseChartCode = line.getChartOfAccountsCode();
53 }
54 else {
55 String currentChartCode = line.getChartOfAccountsCode();
56 if (!currentChartCode.equals(baseChartCode)) {
57 GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DIFFERENT_CHARTS, new String[] {});
58 return false;
59 }
60 }
61 index++;
62 }
63 return true;
64 }
65
66 /**
67 * Gets the accountingDocumentForValidation attribute.
68 * @return Returns the accountingDocumentForValidation.
69 */
70 public AccountingDocument getAccountingDocumentForValidation() {
71 return accountingDocumentForValidation;
72 }
73
74 /**
75 * Sets the accountingDocumentForValidation attribute value.
76 * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
77 */
78 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
79 this.accountingDocumentForValidation = accountingDocumentForValidation;
80 }
81 }