View Javadoc
1   /*
2    * Copyright 2008 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.fp.document.validation.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.fp.businessobject.DisbursementVoucherPayeeDetail;
20  import org.kuali.ole.fp.businessobject.DisbursementVoucherWireTransfer;
21  import org.kuali.ole.fp.document.DisbursementVoucherConstants;
22  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.sys.OLEKeyConstants;
25  import org.kuali.ole.sys.OLEPropertyConstants;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.ole.sys.document.AccountingDocument;
28  import org.kuali.ole.sys.document.validation.GenericValidation;
29  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
30  import org.kuali.rice.kns.service.DictionaryValidationService;
31  import org.kuali.rice.krad.util.GlobalVariables;
32  import org.kuali.rice.krad.util.MessageMap;
33  
34  public class DisbursementVoucherWireTransferValidation extends GenericValidation implements DisbursementVoucherConstants {
35      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherWireTransferValidation.class);
36  
37      private AccountingDocument accountingDocumentForValidation;
38  
39      /**
40       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
41       */
42      public boolean validate(AttributedDocumentEvent event) {
43          LOG.debug("validate start");
44          boolean isValid = true;
45          
46          DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
47          DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
48          DisbursementVoucherWireTransfer wireTransfer = document.getDvWireTransfer();
49  
50          if (!PAYMENT_METHOD_WIRE.equals(document.getDisbVchrPaymentMethodCode())) {
51              return isValid;
52          }
53  
54          MessageMap errors = GlobalVariables.getMessageMap(); 
55          errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
56          errors.addToErrorPath(OLEPropertyConstants.DV_WIRE_TRANSFER);
57          
58          SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(wireTransfer);
59  
60          if (OLEConstants.COUNTRY_CODE_UNITED_STATES.equals(wireTransfer.getDisbVchrBankCountryCode()) && StringUtils.isBlank(wireTransfer.getDisbVchrBankRoutingNumber())) {
61              errors.putError(OLEPropertyConstants.DISB_VCHR_BANK_ROUTING_NUMBER, OLEKeyConstants.ERROR_DV_BANK_ROUTING_NUMBER);
62              isValid = false;
63          }
64  
65          if (OLEConstants.COUNTRY_CODE_UNITED_STATES.equals(wireTransfer.getDisbVchrBankCountryCode()) && StringUtils.isBlank(wireTransfer.getDisbVchrBankStateCode())) {
66              errors.putError(OLEPropertyConstants.DISB_VCHR_BANK_STATE_CODE, OLEKeyConstants.ERROR_REQUIRED, "Bank State");
67              isValid = false;
68          }
69  
70          /* cannot have attachment checked for wire transfer */
71          if (document.isDisbVchrAttachmentCode()) {
72              errors.putErrorWithoutFullErrorPath(OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.DISB_VCHR_ATTACHMENT_CODE, OLEKeyConstants.ERROR_DV_WIRE_ATTACHMENT);
73              isValid = false;
74          }
75  
76          errors.removeFromErrorPath(OLEPropertyConstants.DV_WIRE_TRANSFER);
77          errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
78          
79          return isValid;
80      }
81  
82      /**
83       * Gets the accountingDocumentForValidation attribute. 
84       * @return Returns the accountingDocumentForValidation.
85       */
86      public AccountingDocument getAccountingDocumentForValidation() {
87          return accountingDocumentForValidation;
88      }
89  
90      /**
91       * Sets the accountingDocumentForValidation attribute value.
92       * 
93       * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
94       */
95      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
96          this.accountingDocumentForValidation = accountingDocumentForValidation;
97      }
98  }