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.document.DisbursementVoucherConstants;
20  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
21  import org.kuali.ole.sys.OLEKeyConstants;
22  import org.kuali.ole.sys.OLEPropertyConstants;
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.rice.krad.util.GlobalVariables;
27  import org.kuali.rice.krad.util.MessageMap;
28  
29  public class DisbursementVoucherForeignDraftValidation extends GenericValidation implements DisbursementVoucherConstants {
30      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherEmployeeInformationValidation.class);
31  
32      private AccountingDocument accountingDocumentForValidation;
33  
34      /**
35       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
36       */
37      public boolean validate(AttributedDocumentEvent event) {
38          LOG.debug("validate start");
39          boolean isValid = true;
40          
41          DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
42          if (!PAYMENT_METHOD_DRAFT.equals(document.getDisbVchrPaymentMethodCode())) {
43              return true;
44          }
45  
46          MessageMap errors = GlobalVariables.getMessageMap();
47          errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
48          errors.addToErrorPath(OLEPropertyConstants.DV_WIRE_TRANSFER);
49  
50          /* currency type code required */
51          if (StringUtils.isBlank(document.getDvWireTransfer().getDisbursementVoucherForeignCurrencyTypeCode())) {
52              errors.putError(OLEPropertyConstants.DISB_VCHR_FD_CURRENCY_TYPE_CODE, OLEKeyConstants.ERROR_DV_CURRENCY_TYPE_CODE);
53              isValid = false;
54          }
55  
56          /* currency type name required */
57          if (StringUtils.isBlank(document.getDvWireTransfer().getDisbursementVoucherForeignCurrencyTypeName())) {
58              errors.putError(OLEPropertyConstants.DISB_VCHR_FD_CURRENCY_TYPE_NAME, OLEKeyConstants.ERROR_DV_CURRENCY_TYPE_NAME);
59              isValid = false;
60          }
61  
62          errors.removeFromErrorPath(OLEPropertyConstants.DV_WIRE_TRANSFER);
63          errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
64  
65          return isValid;
66      }
67  
68      /**
69       * Sets the accountingDocumentForValidation attribute value.
70       * 
71       * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
72       */
73      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
74          this.accountingDocumentForValidation = accountingDocumentForValidation;
75      }
76  
77      /**
78       * Gets the accountingDocumentForValidation attribute. 
79       * @return Returns the accountingDocumentForValidation.
80       */
81      public AccountingDocument getAccountingDocumentForValidation() {
82          return accountingDocumentForValidation;
83      }
84  }