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.EndowmentTransactionLinesDocument; 020 import org.kuali.kfs.module.endow.document.GLToEndowmentTransferOfFundsDocument; 021 import org.kuali.kfs.module.endow.document.service.EndowmentTransactionLinesDocumentService; 022 import org.kuali.kfs.sys.context.SpringContext; 023 import org.kuali.rice.kns.document.Document; 024 025 public class GLToEndowmentTransferOfFundsDocumentRules extends EndowmentAccountingLinesDocumentBaseRules { 026 027 /** 028 * @see org.kuali.kfs.module.endow.document.validation.impl.EndowmentTransactionLinesDocumentBaseRules#validateTransactionLine(org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocument, 029 * org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine, int) 030 */ 031 @Override 032 protected boolean validateTransactionLine(EndowmentTransactionLinesDocument endowmentTransactionLinesDocument, EndowmentTransactionLine line, int index) { 033 boolean isValid = super.validateTransactionLine(endowmentTransactionLinesDocument, line, index); 034 // Obtain Prefix for Error fields in UI. 035 String ERROR_PREFIX = getErrorPrefix(line, index); 036 037 if (isValid) { 038 039 // Is Etran code empty 040 if (isEndowmentTransactionCodeEmpty(line, ERROR_PREFIX)) 041 return false; 042 043 // Validate ETran code 044 if (!validateEndowmentTransactionCode(line, ERROR_PREFIX)) 045 return false; 046 047 // Validate ETran code as E or I 048 isValid &= validateEndowmentTransactionTypeCode(endowmentTransactionLinesDocument, line, ERROR_PREFIX); 049 050 // Validate if a KEMID can have a principal transaction when IP indicator is P 051 if (!canKEMIDHaveAPrincipalTransaction(line, ERROR_PREFIX)) 052 return false; 053 054 // Validate if the chart is matched between the KEMID and EtranCode 055 isValid &= validateChartMatch(line, ERROR_PREFIX); 056 057 // Validate Amount is Greater than Zero. 058 isValid &= validateTransactionAmountGreaterThanZero(line, ERROR_PREFIX); 059 060 // Set Corpus Indicator 061 line.setCorpusIndicator(SpringContext.getBean(EndowmentTransactionLinesDocumentService.class).getCorpusIndicatorValueforAnEndowmentTransactionLine(line.getKemid(), line.getEtranCode(), line.getTransactionIPIndicatorCode())); 062 063 } 064 065 return isValid; 066 } 067 068 /** 069 * @see org.kuali.rice.kns.rules.DocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.Document) 070 */ 071 @Override 072 protected boolean processCustomRouteDocumentBusinessRules(Document document) { 073 boolean isValid = super.processCustomRouteDocumentBusinessRules(document); 074 GLToEndowmentTransferOfFundsDocument transferOfFundsDocument = (GLToEndowmentTransferOfFundsDocument) document; 075 076 // validate the document has at least one target transaction line 077 if (!transactionLineSizeGreaterThanZero(transferOfFundsDocument, false)) 078 return false; 079 080 // validate that the document has at least one source accounting line 081 if (!validateAccountingLinesSizeGreaterThanZero(transferOfFundsDocument, true)) { 082 return false; 083 } 084 085 return isValid; 086 } 087 088 }