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.CashDecreaseDocument;
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 CashDecreaseDocumentRules 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 CashDecreaseDocument cashDecreaseDocument = (CashDecreaseDocument) document;
032
033 // Validate at least one Tx was entered.
034 if (!transactionLineSizeGreaterThanZero(cashDecreaseDocument, true))
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(cashDecreaseDocument, true)) {
044 if (!validateSecurityCode(cashDecreaseDocument, true))
045 return false;
046 }
047
048 for (int i = 0; i < cashDecreaseDocument.getSourceTransactionLines().size(); i++) {
049 EndowmentTransactionLine txLine = cashDecreaseDocument.getSourceTransactionLines().get(i);
050 isValid &= validateCashTransactionLine(cashDecreaseDocument, txLine, i);
051 }
052 }
053
054 return isValid;
055 }
056
057 /**
058 * @see org.kuali.kfs.module.endow.document.validation.impl.CashDocumentBaseRules# (
059 * org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine)
060 */
061 @Override
062 protected boolean validateCashTransactionLine(EndowmentTransactionLinesDocument document, EndowmentTransactionLine line, int index) {
063 boolean isValid = super.validateCashTransactionLine(document, line, index);
064 isValid &= !GlobalVariables.getMessageMap().hasErrors();
065
066 if (isValid) {
067 // Obtain Prefix for Error fields in UI.
068 String ERROR_PREFIX = getErrorPrefix(line, index);
069
070 checkWhetherReducePermanentlyRestrictedFund(line, ERROR_PREFIX);
071 checkWhetherHaveSufficientFundsForCashBasedTransaction(line, ERROR_PREFIX);
072 }
073 return GlobalVariables.getMessageMap().getErrorCount() == 0;
074 }
075
076 /**
077 * @see org.kuali.kfs.module.endow.document.validation.impl.EndowmentTransactionLinesDocumentBaseRules#validateEndowmentTransactionTypeCode(org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocument, org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine, java.lang.String)
078 */
079 @Override
080 protected boolean validateEndowmentTransactionTypeCode(EndowmentTransactionLinesDocument endowmentTransactionLinesDocument, EndowmentTransactionLine line, String prefix) {
081
082 return super.validateEtranTypeBasedOnDocSource(endowmentTransactionLinesDocument, line, prefix);
083 }
084
085 }