001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.fp.document.validation.impl;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.kfs.fp.businessobject.DisbursementVoucherPayeeDetail;
020 import org.kuali.kfs.fp.document.DisbursementVoucherDocument;
021 import org.kuali.kfs.sys.KFSKeyConstants;
022 import org.kuali.kfs.sys.KFSPropertyConstants;
023 import org.kuali.kfs.sys.context.SpringContext;
024 import org.kuali.kfs.sys.document.AccountingDocument;
025 import org.kuali.kfs.sys.document.validation.GenericValidation;
026 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
027 import org.kuali.rice.kns.service.DataDictionaryService;
028 import org.kuali.rice.kns.util.GlobalVariables;
029 import org.kuali.rice.kns.util.MessageMap;
030 import org.kuali.rice.kns.util.ObjectUtils;
031
032 public class DisbursementVoucherPayeeAddressValidation extends GenericValidation {
033 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPayeeAddressValidation.class);
034
035 private AccountingDocument accountingDocumentForValidation;
036
037 /**
038 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
039 */
040 public boolean validate(AttributedDocumentEvent event) {
041 LOG.debug("validate start");
042 boolean isValid = true;
043
044 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
045 DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
046
047 MessageMap errors = GlobalVariables.getMessageMap();
048 errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
049
050 DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
051
052 String stateCode = payeeDetail.getDisbVchrPayeeStateCode();
053 if (StringUtils.isNotBlank(stateCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeeState())) {
054 String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_STATE_CODE);
055 String propertyPath = KFSPropertyConstants.DV_PAYEE_DETAIL + "." + KFSPropertyConstants.DISB_VCHR_PAYEE_STATE_CODE;
056 errors.putError(propertyPath, KFSKeyConstants.ERROR_EXISTENCE, label);
057 isValid = false;
058 }
059
060 String zipCode = payeeDetail.getDisbVchrPayeeZipCode();
061 if (StringUtils.isNotBlank(zipCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeePostalZipCode())) {
062 String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ZIP_CODE);
063 String propertyPath = KFSPropertyConstants.DV_PAYEE_DETAIL + "." + KFSPropertyConstants.DISB_VCHR_PAYEE_ZIP_CODE;
064 errors.putError(propertyPath, KFSKeyConstants.ERROR_EXISTENCE, label);
065 isValid = false;
066 }
067
068 String countryCode = payeeDetail.getDisbVchrPayeeCountryCode();
069 if (StringUtils.isNotBlank(countryCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeeCountry())) {
070 String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_COUNTRY_CODE);
071 String propertyPath = KFSPropertyConstants.DV_PAYEE_DETAIL + "." + KFSPropertyConstants.DISB_VCHR_PAYEE_COUNTRY_CODE;
072 errors.putError(propertyPath, KFSKeyConstants.ERROR_EXISTENCE, label);
073 isValid = false;
074 }
075
076 errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
077
078 return isValid;
079 }
080
081
082 /**
083 * Gets the accountingDocumentForValidation attribute.
084 * @return Returns the accountingDocumentForValidation.
085 */
086 public AccountingDocument getAccountingDocumentForValidation() {
087 return accountingDocumentForValidation;
088 }
089
090
091 /**
092 * Sets the accountingDocumentForValidation attribute value.
093 *
094 * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
095 */
096 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
097 this.accountingDocumentForValidation = accountingDocumentForValidation;
098 }
099 }