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.kuali.kfs.sys.KFSKeyConstants;
019    import org.kuali.kfs.sys.document.service.DebitDeterminerService;
020    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
021    import org.kuali.kfs.sys.document.validation.impl.AccountingLineValueAllowedValidation;
022    import org.kuali.rice.kns.util.GlobalVariables;
023    
024    /**
025     * A validation for the transfer of funds document that makes sure that an object code in any accounting line represents either income or expense.
026     */
027    public class TransferOfFundsObjectCodeValueAllowedValidation extends AccountingLineValueAllowedValidation {
028        private DebitDeterminerService debitDeterminerService;
029    
030        /**
031         * Overrides the parent to make sure that the chosen object code's object code is Income/Expense.
032         * @see org.kuali.kfs.sys.document.validation.impl.AccountingLineValueAllowedValidation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
033         */
034        @Override
035        public boolean validate(AttributedDocumentEvent event) {
036            // TODO JAMES DO WE NEED THIS YET?
037            boolean isObjectCodeAllowed = super.validate(event);
038    
039            if (!debitDeterminerService.isIncome(getAccountingLineForValidation()) && !debitDeterminerService.isExpense(getAccountingLineForValidation())) {
040                GlobalVariables.getMessageMap().putError("financialObjectCode", KFSKeyConstants.ERROR_DOCUMENT_TOF_INVALID_OBJECT_TYPE_CODES, new String[] { getAccountingLineForValidation().getObjectCode().getFinancialObjectTypeCode(), getAccountingLineForValidation().getObjectCode().getFinancialObjectSubTypeCode() });
041                isObjectCodeAllowed = false;
042            }
043    
044            return isObjectCodeAllowed;
045        }
046    
047        /**
048         * Gets the debitDeterminerService attribute. 
049         * @return Returns the debitDeterminerService.
050         */
051        public DebitDeterminerService getDebitDeterminerService() {
052            return debitDeterminerService;
053        }
054    
055        /**
056         * Sets the debitDeterminerService attribute value.
057         * @param debitDeterminerService The debitDeterminerService to set.
058         */
059        public void setDebitDeterminerService(DebitDeterminerService debitDeterminerService) {
060            this.debitDeterminerService = debitDeterminerService;
061        }
062    }