001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.fp.document.validation.impl;
017    
018    import org.kuali.kfs.sys.KFSConstants;
019    import org.kuali.kfs.sys.KFSKeyConstants;
020    import org.kuali.kfs.sys.document.AccountingDocument;
021    import org.kuali.kfs.sys.document.validation.GenericValidation;
022    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
023    import org.kuali.rice.kns.util.GlobalVariables;
024    
025    /**
026     * The Budget Adjustment's variation on the lines required for routing met validation - here, we just need
027     * to make sure that the total number of accounting lines on the document is greater than 0.
028     */
029    public class BudgetAdjustmentAccountingLinesRequiredForRoutingValidation extends GenericValidation {
030        private AccountingDocument accountingDocumentForValidation;
031    
032        /**
033         * The BA document does not have to have source accounting lines. In the case of setting up a budget for a new account, only targets
034         * line (increase section) are setup.
035         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
036         */
037        public boolean validate(AttributedDocumentEvent event) {
038            // check that both source and target are not empty, in which case is an error
039            if (getAccountingDocumentForValidation().getSourceAccountingLines().isEmpty() && getAccountingDocumentForValidation().getTargetAccountingLines().isEmpty()) {
040                GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNTING_LINE_ERRORS, KFSKeyConstants.ERROR_DOCUMENT_NO_ACCOUNTING_LINES);
041                return false;
042            }
043    
044            return true;
045        }
046    
047        /**
048         * Gets the accountingDocumentForValidation attribute. 
049         * @return Returns the accountingDocumentForValidation.
050         */
051        public AccountingDocument getAccountingDocumentForValidation() {
052            return accountingDocumentForValidation;
053        }
054    
055        /**
056         * Sets the accountingDocumentForValidation attribute value.
057         * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
058         */
059        public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
060            this.accountingDocumentForValidation = accountingDocumentForValidation;
061        }
062    }