001/* 002 * Copyright 2008 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 */ 016package org.kuali.ole.fp.document.validation.impl; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.ole.fp.document.DisbursementVoucherConstants; 020import org.kuali.ole.fp.document.DisbursementVoucherDocument; 021import org.kuali.ole.sys.OLEKeyConstants; 022import org.kuali.ole.sys.OLEPropertyConstants; 023import org.kuali.ole.sys.document.AccountingDocument; 024import org.kuali.ole.sys.document.validation.GenericValidation; 025import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent; 026import org.kuali.rice.krad.util.GlobalVariables; 027import org.kuali.rice.krad.util.MessageMap; 028 029public class DisbursementVoucherForeignDraftValidation extends GenericValidation implements DisbursementVoucherConstants { 030 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherEmployeeInformationValidation.class); 031 032 private AccountingDocument accountingDocumentForValidation; 033 034 /** 035 * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent) 036 */ 037 public boolean validate(AttributedDocumentEvent event) { 038 LOG.debug("validate start"); 039 boolean isValid = true; 040 041 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation; 042 if (!PAYMENT_METHOD_DRAFT.equals(document.getDisbVchrPaymentMethodCode())) { 043 return true; 044 } 045 046 MessageMap errors = GlobalVariables.getMessageMap(); 047 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT); 048 errors.addToErrorPath(OLEPropertyConstants.DV_WIRE_TRANSFER); 049 050 /* currency type code required */ 051 if (StringUtils.isBlank(document.getDvWireTransfer().getDisbursementVoucherForeignCurrencyTypeCode())) { 052 errors.putError(OLEPropertyConstants.DISB_VCHR_FD_CURRENCY_TYPE_CODE, OLEKeyConstants.ERROR_DV_CURRENCY_TYPE_CODE); 053 isValid = false; 054 } 055 056 /* currency type name required */ 057 if (StringUtils.isBlank(document.getDvWireTransfer().getDisbursementVoucherForeignCurrencyTypeName())) { 058 errors.putError(OLEPropertyConstants.DISB_VCHR_FD_CURRENCY_TYPE_NAME, OLEKeyConstants.ERROR_DV_CURRENCY_TYPE_NAME); 059 isValid = false; 060 } 061 062 errors.removeFromErrorPath(OLEPropertyConstants.DV_WIRE_TRANSFER); 063 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT); 064 065 return isValid; 066 } 067 068 /** 069 * Sets the accountingDocumentForValidation attribute value. 070 * 071 * @param accountingDocumentForValidation The accountingDocumentForValidation to set. 072 */ 073 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) { 074 this.accountingDocumentForValidation = accountingDocumentForValidation; 075 } 076 077 /** 078 * Gets the accountingDocumentForValidation attribute. 079 * @return Returns the accountingDocumentForValidation. 080 */ 081 public AccountingDocument getAccountingDocumentForValidation() { 082 return accountingDocumentForValidation; 083 } 084}