View Javadoc
1   /*
2    * Copyright 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.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.document.DisbursementVoucherDocument;
21  import org.kuali.ole.sys.OLEKeyConstants;
22  import org.kuali.ole.sys.OLEPropertyConstants;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.ole.sys.document.AccountingDocument;
25  import org.kuali.ole.sys.document.validation.GenericValidation;
26  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27  import org.kuali.rice.kns.service.DataDictionaryService;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  import org.kuali.rice.krad.util.MessageMap;
30  import org.kuali.rice.krad.util.ObjectUtils;
31  
32  public class DisbursementVoucherPayeeAddressValidation extends GenericValidation {
33      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPayeeAddressValidation.class);
34  
35      private AccountingDocument accountingDocumentForValidation;
36  
37      /**
38       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
39       */
40      public boolean validate(AttributedDocumentEvent event) {
41          LOG.debug("validate start");
42          boolean isValid = true;
43  
44          DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
45          DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
46  
47          MessageMap errors = GlobalVariables.getMessageMap();
48          errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
49  
50          DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
51          
52          String stateCode = payeeDetail.getDisbVchrPayeeStateCode();
53          if (StringUtils.isNotBlank(stateCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeeState())) {
54              String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_STATE_CODE);
55              String propertyPath = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_STATE_CODE;
56              errors.putError(propertyPath, OLEKeyConstants.ERROR_EXISTENCE, label);
57              isValid = false;
58          }
59  
60          String zipCode = payeeDetail.getDisbVchrPayeeZipCode();
61          if (StringUtils.isNotBlank(zipCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeePostalZipCode())) {
62              String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_ZIP_CODE);
63              String propertyPath = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_ZIP_CODE;
64              errors.putError(propertyPath, OLEKeyConstants.ERROR_EXISTENCE, label);
65              isValid = false;
66          }
67  
68          String countryCode = payeeDetail.getDisbVchrPayeeCountryCode();
69          if (StringUtils.isNotBlank(countryCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeeCountry())) {
70              String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_COUNTRY_CODE);
71              String propertyPath = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_COUNTRY_CODE;
72              errors.putError(propertyPath, OLEKeyConstants.ERROR_EXISTENCE, label);
73              isValid = false;
74          }
75  
76          errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
77  
78          return isValid;
79      }
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      /**
92       * Sets the accountingDocumentForValidation attribute value.
93       * 
94       * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
95       */
96      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
97          this.accountingDocumentForValidation = accountingDocumentForValidation;
98      }
99  }