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.endow.document.validation.impl;
017    
018    import org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine;
019    import org.kuali.kfs.module.endow.document.CashIncreaseDocument;
020    import org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocument;
021    import org.kuali.rice.kns.document.Document;
022    import org.kuali.rice.kns.util.GlobalVariables;
023    
024    public class CashIncreaseDocumentRules extends CashDocumentBaseRules {
025    
026        /**
027         * @see org.kuali.rice.kns.rules.DocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.Document)
028         */
029        @Override
030        public boolean processCustomRouteDocumentBusinessRules(Document document) {
031            CashIncreaseDocument cashIncreaseDocument = (CashIncreaseDocument) document;
032    
033            // Validate at least one Tx was entered.
034            if (!transactionLineSizeGreaterThanZero(cashIncreaseDocument, false))
035                return false;
036    
037            boolean isValid = super.processCustomRouteDocumentBusinessRules(document);
038            isValid &= !GlobalVariables.getMessageMap().hasErrors();
039    
040            if (isValid) {
041    
042                // Checks if Security field is not empty, security code must be valid.
043                if (!isSecurityCodeEmpty(cashIncreaseDocument, true)) {
044                    if (!validateSecurityCode(cashIncreaseDocument, true))
045                        return false;
046                }
047    
048                for (int i = 0; i < cashIncreaseDocument.getTargetTransactionLines().size(); i++) {
049                    EndowmentTransactionLine txLine = cashIncreaseDocument.getTargetTransactionLines().get(i);
050                    isValid &= validateCashTransactionLine(cashIncreaseDocument, txLine, i);
051                }
052            }
053    
054            return isValid;
055        }
056    
057        /**
058         * @see org.kuali.kfs.module.endow.document.validation.impl.EndowmentTransactionLinesDocumentBaseRules#validateEndowmentTransactionTypeCode(org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocument,
059         *      org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine, java.lang.String)
060         */
061        @Override
062        protected boolean validateEndowmentTransactionTypeCode(EndowmentTransactionLinesDocument endowmentTransactionLinesDocument, EndowmentTransactionLine line, String prefix) {
063    
064            return validateEtranTypeBasedOnDocSource(endowmentTransactionLinesDocument, line, prefix);
065        }
066    }