View Javadoc
1   /*
2    * Copyright 2008-2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapPropertyConstants;
19  import org.kuali.ole.module.purap.document.AccountsPayableDocumentBase;
20  import org.kuali.ole.sys.OLEParameterKeyConstants;
21  import org.kuali.ole.sys.businessobject.Bank;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.ole.sys.document.AccountingDocument;
24  import org.kuali.ole.sys.document.validation.GenericValidation;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.ole.sys.document.validation.impl.BankCodeValidation;
27  import org.kuali.rice.core.api.parameter.ParameterEvaluator;
28  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
29  
30  public class AccountsPayableBankCodeValidation extends GenericValidation {
31      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountsPayableBankCodeValidation.class);
32  
33      private AccountingDocument accountingDocumentForValidation;
34  
35      /**
36       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
37       */
38      public boolean validate(AttributedDocumentEvent event) {
39          LOG.debug("validate start");
40  
41          AccountsPayableDocumentBase apDocument = (AccountsPayableDocumentBase) accountingDocumentForValidation;
42  
43          boolean isValid = true;
44          if (isDocumentTypeUsingBankCode(apDocument)) {
45              isValid = BankCodeValidation.validate(apDocument, apDocument.getBankCode(), PurapPropertyConstants.BANK_CODE, false, true);
46          }
47  
48          return isValid;
49      }
50  
51      /**
52       * Verify that this document is using bank codes before validating.
53       *
54       * @param apDocument
55       * @return true if {@link OLEParameterKeyConstants.BANK_CODE_DOCUMENT_TYPES} contains this document type
56       */
57      private boolean isDocumentTypeUsingBankCode(AccountsPayableDocumentBase apDocument) {
58          String documentTypeName = apDocument.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
59          ParameterEvaluator evaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Bank.class, OLEParameterKeyConstants.BANK_CODE_DOCUMENT_TYPES, documentTypeName);
60          return evaluator.evaluationSucceeds();
61      }
62  
63      /**
64       * Sets the accountingDocumentForValidation attribute value.
65       *
66       * @param accountingDocumentForValidation
67       *         The accountingDocumentForValidation to set.
68       */
69      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
70          this.accountingDocumentForValidation = accountingDocumentForValidation;
71      }
72  
73      /**
74       * Gets the accountingDocumentForValidation attribute.
75       *
76       * @return Returns the accountingDocumentForValidation.
77       */
78      public AccountingDocument getAccountingDocumentForValidation() {
79          return accountingDocumentForValidation;
80      }
81  }