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.sys.document.validation.impl;
017    
018    import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
019    
020    import org.kuali.kfs.sys.KFSKeyConstants;
021    import org.kuali.kfs.sys.KFSPropertyConstants;
022    import org.kuali.kfs.sys.document.AccountingDocument;
023    import org.kuali.kfs.sys.document.validation.GenericValidation;
024    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
025    import org.kuali.rice.kns.util.GlobalVariables;
026    
027    /**
028     * Validation which checks a one-sided accounting document (ie, an accounting document which only uses source accounting lines, not target)
029     * has a required number of accounting lines.
030     */
031    public class OneSidedRequiredAccountingLinesCountValidation extends GenericValidation {
032        private AccountingDocument accountingDocumentForValidation;
033        private int requiredMinimumCount = 1; // default - you need at least one accounting line
034    
035        /**
036         * Validates that the accountingDocumentForValidation has at least the requiredMinimumCount accounting lines
037         * in its sourceAccountingLines (yep, it's assumed that one-sided accounting docs *always* use source...isn't that dumb?)
038         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
039         */
040        public boolean validate(AttributedDocumentEvent event) {
041            if (getAccountingDocumentForValidation().getSourceAccountingLines().size() < getRequiredMinimumCount()) {
042                GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + KFSPropertyConstants.SOURCE_ACCOUNTING_LINES, KFSKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINES_NO_SINGLE_SECTION_ACCOUNTING_LINES);
043                return false;
044            }
045            return true;
046        }
047    
048        /**
049         * Gets the accountingDocumentForValdation attribute. 
050         * @return Returns the accountingDocumentForValdation.
051         */
052        public AccountingDocument getAccountingDocumentForValidation() {
053            return accountingDocumentForValidation;
054        }
055    
056        /**
057         * Sets the accountingDocumentForValdation attribute value.
058         * @param accountingDocumentForValdation The accountingDocumentForValdation to set.
059         */
060        public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
061            this.accountingDocumentForValidation = accountingDocumentForValidation;
062        }
063    
064        /**
065         * Gets the requiredMinimumCount attribute. 
066         * @return Returns the requiredMinimumCount.
067         */
068        public int getRequiredMinimumCount() {
069            return requiredMinimumCount;
070        }
071    
072        /**
073         * Sets the requiredMinimumCount attribute value.
074         * @param requiredMinimumCount The requiredMinimumCount to set.
075         */
076        public void setRequiredMinimumCount(int requiredCount) {
077            this.requiredMinimumCount = requiredCount;
078        }
079    }