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.businessobject.DisbursementVoucherWireTransfer;
021 import org.kuali.kfs.fp.document.DisbursementVoucherConstants;
022 import org.kuali.kfs.fp.document.DisbursementVoucherDocument;
023 import org.kuali.kfs.sys.KFSConstants;
024 import org.kuali.kfs.sys.KFSKeyConstants;
025 import org.kuali.kfs.sys.KFSPropertyConstants;
026 import org.kuali.kfs.sys.context.SpringContext;
027 import org.kuali.kfs.sys.document.AccountingDocument;
028 import org.kuali.kfs.sys.document.validation.GenericValidation;
029 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
030 import org.kuali.rice.kns.service.DictionaryValidationService;
031 import org.kuali.rice.kns.util.GlobalVariables;
032 import org.kuali.rice.kns.util.MessageMap;
033
034 public class DisbursementVoucherWireTransferValidation extends GenericValidation implements DisbursementVoucherConstants {
035 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherWireTransferValidation.class);
036
037 private AccountingDocument accountingDocumentForValidation;
038
039 /**
040 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
041 */
042 public boolean validate(AttributedDocumentEvent event) {
043 LOG.debug("validate start");
044 boolean isValid = true;
045
046 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
047 DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
048 DisbursementVoucherWireTransfer wireTransfer = document.getDvWireTransfer();
049
050 if (!PAYMENT_METHOD_WIRE.equals(document.getDisbVchrPaymentMethodCode())) {
051 return isValid;
052 }
053
054 MessageMap errors = GlobalVariables.getMessageMap();
055 errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
056 errors.addToErrorPath(KFSPropertyConstants.DV_WIRE_TRANSFER);
057
058 SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(wireTransfer);
059
060 if (KFSConstants.COUNTRY_CODE_UNITED_STATES.equals(wireTransfer.getDisbVchrBankCountryCode()) && StringUtils.isBlank(wireTransfer.getDisbVchrBankRoutingNumber())) {
061 errors.putError(KFSPropertyConstants.DISB_VCHR_BANK_ROUTING_NUMBER, KFSKeyConstants.ERROR_DV_BANK_ROUTING_NUMBER);
062 isValid = false;
063 }
064
065 if (KFSConstants.COUNTRY_CODE_UNITED_STATES.equals(wireTransfer.getDisbVchrBankCountryCode()) && StringUtils.isBlank(wireTransfer.getDisbVchrBankStateCode())) {
066 errors.putError(KFSPropertyConstants.DISB_VCHR_BANK_STATE_CODE, KFSKeyConstants.ERROR_REQUIRED, "Bank State");
067 isValid = false;
068 }
069
070 /* cannot have attachment checked for wire transfer */
071 if (document.isDisbVchrAttachmentCode()) {
072 errors.putErrorWithoutFullErrorPath(KFSPropertyConstants.DOCUMENT + "." + KFSPropertyConstants.DISB_VCHR_ATTACHMENT_CODE, KFSKeyConstants.ERROR_DV_WIRE_ATTACHMENT);
073 isValid = false;
074 }
075
076 errors.removeFromErrorPath(KFSPropertyConstants.DV_WIRE_TRANSFER);
077 errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
078
079 return isValid;
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 * Sets the accountingDocumentForValidation attribute value.
092 *
093 * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
094 */
095 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
096 this.accountingDocumentForValidation = accountingDocumentForValidation;
097 }
098 }