001/* 002 * Copyright 2008-2009 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 */ 016package org.kuali.ole.module.purap.document.validation.impl; 017 018import org.kuali.ole.module.purap.PurapPropertyConstants; 019import org.kuali.ole.module.purap.document.AccountsPayableDocumentBase; 020import org.kuali.ole.sys.OLEParameterKeyConstants; 021import org.kuali.ole.sys.businessobject.Bank; 022import org.kuali.ole.sys.context.SpringContext; 023import org.kuali.ole.sys.document.AccountingDocument; 024import org.kuali.ole.sys.document.validation.GenericValidation; 025import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent; 026import org.kuali.ole.sys.document.validation.impl.BankCodeValidation; 027import org.kuali.rice.core.api.parameter.ParameterEvaluator; 028import org.kuali.rice.core.api.parameter.ParameterEvaluatorService; 029 030public class AccountsPayableBankCodeValidation extends GenericValidation { 031 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountsPayableBankCodeValidation.class); 032 033 private AccountingDocument accountingDocumentForValidation; 034 035 /** 036 * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent) 037 */ 038 public boolean validate(AttributedDocumentEvent event) { 039 LOG.debug("validate start"); 040 041 AccountsPayableDocumentBase apDocument = (AccountsPayableDocumentBase) accountingDocumentForValidation; 042 043 boolean isValid = true; 044 if (isDocumentTypeUsingBankCode(apDocument)) { 045 isValid = BankCodeValidation.validate(apDocument, apDocument.getBankCode(), PurapPropertyConstants.BANK_CODE, false, true); 046 } 047 048 return isValid; 049 } 050 051 /** 052 * Verify that this document is using bank codes before validating. 053 * 054 * @param apDocument 055 * @return true if {@link OLEParameterKeyConstants.BANK_CODE_DOCUMENT_TYPES} contains this document type 056 */ 057 private boolean isDocumentTypeUsingBankCode(AccountsPayableDocumentBase apDocument) { 058 String documentTypeName = apDocument.getDocumentHeader().getWorkflowDocument().getDocumentTypeName(); 059 ParameterEvaluator evaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Bank.class, OLEParameterKeyConstants.BANK_CODE_DOCUMENT_TYPES, documentTypeName); 060 return evaluator.evaluationSucceeds(); 061 } 062 063 /** 064 * Sets the accountingDocumentForValidation attribute value. 065 * 066 * @param accountingDocumentForValidation 067 * The accountingDocumentForValidation to set. 068 */ 069 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) { 070 this.accountingDocumentForValidation = accountingDocumentForValidation; 071 } 072 073 /** 074 * Gets the accountingDocumentForValidation attribute. 075 * 076 * @return Returns the accountingDocumentForValidation. 077 */ 078 public AccountingDocument getAccountingDocumentForValidation() { 079 return accountingDocumentForValidation; 080 } 081}