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.document.DisbursementVoucherConstants;
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.document.AccountingDocument;
024    import org.kuali.kfs.sys.document.validation.GenericValidation;
025    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
026    import org.kuali.rice.kns.util.GlobalVariables;
027    import org.kuali.rice.kns.util.MessageMap;
028    
029    public 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.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.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(KFSPropertyConstants.DOCUMENT);
048            errors.addToErrorPath(KFSPropertyConstants.DV_WIRE_TRANSFER);
049    
050            /* currency type code required */
051            if (StringUtils.isBlank(document.getDvWireTransfer().getDisbursementVoucherForeignCurrencyTypeCode())) {
052                errors.putError(KFSPropertyConstants.DISB_VCHR_FD_CURRENCY_TYPE_CODE, KFSKeyConstants.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(KFSPropertyConstants.DISB_VCHR_FD_CURRENCY_TYPE_NAME, KFSKeyConstants.ERROR_DV_CURRENCY_TYPE_NAME);
059                isValid = false;
060            }
061    
062            errors.removeFromErrorPath(KFSPropertyConstants.DV_WIRE_TRANSFER);
063            errors.removeFromErrorPath(KFSPropertyConstants.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    }