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.sys.OLEConstants;
21 import org.kuali.ole.sys.OLEKeyConstants;
22 import org.kuali.ole.sys.businessobject.AccountingLine;
23 import org.kuali.ole.sys.document.AccountingDocument;
24 import org.kuali.ole.sys.document.validation.GenericValidation;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.rice.krad.util.GlobalVariables;
27
28 /**
29 * Validation for Auxiliary Voucher that checks that all the source accounting lines on the document use
30 * only one sub fund group among them.
31 */
32 public class AuxiliaryVoucherSingleSubFundValidation 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 Sub-Fund Group.
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 baseSubFundGroupCode = null;
44 int index = 0;
45
46 List<AccountingLine> lines = getAccountingDocumentForValidation().getSourceAccountingLines();
47 for (AccountingLine line : lines) {
48 if (index == 0) {
49 baseSubFundGroupCode = line.getAccount().getSubFundGroupCode();
50 }
51 else {
52 String currentSubFundGroup = line.getAccount().getSubFundGroupCode();
53 if (!currentSubFundGroup.equals(baseSubFundGroupCode)) {
54 GlobalVariables.getMessageMap().putError(OLEConstants.ACCOUNTING_LINE_ERRORS, OLEKeyConstants.AuxiliaryVoucher.ERROR_DIFFERENT_SUB_FUND_GROUPS);
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 }