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.module.cam.document.validation.impl;
017    
018    import static org.kuali.kfs.sys.KFSConstants.SOURCE_ACCOUNTING_LINE_ERRORS;
019    import static org.kuali.kfs.sys.KFSKeyConstants.ERROR_DOCUMENT_SOURCE_SECTION_NO_ACCOUNTING_LINES;
020    
021    import org.kuali.kfs.sys.document.AccountingDocument;
022    import org.kuali.kfs.sys.document.validation.GenericValidation;
023    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
024    import org.kuali.rice.kns.util.GlobalVariables;
025    
026    /**
027     * This class validates to make sure that at least one payment line is available for the document
028     */
029    public class AssetPaymentAccountingLineCountValidation extends GenericValidation {
030    
031        /**
032         * Validate accounting line count to ensure minimum of one line
033         * 
034         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
035         */
036        public boolean validate(AttributedDocumentEvent event) {
037            boolean valid = true;
038            AccountingDocument accountingDocument = (AccountingDocument) event.getDocument();
039            if (0 == accountingDocument.getSourceAccountingLines().size()) {
040                GlobalVariables.getMessageMap().putError(SOURCE_ACCOUNTING_LINE_ERRORS, ERROR_DOCUMENT_SOURCE_SECTION_NO_ACCOUNTING_LINES, new String[] { accountingDocument.getSourceAccountingLinesSectionTitle() });
041                valid = false;
042            }
043            else {
044                valid = true;
045            }
046            return valid;
047        }
048    }