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.coa.businessobject.Account;
020import org.kuali.ole.fp.businessobject.BudgetAdjustmentAccountingLine;
021import org.kuali.ole.sys.OLEConstants;
022import org.kuali.ole.sys.OLEKeyConstants;
023import org.kuali.ole.sys.OLEPropertyConstants;
024import org.kuali.ole.sys.context.SpringContext;
025import org.kuali.ole.sys.document.validation.GenericValidation;
026import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
027import org.kuali.rice.coreservice.framework.parameter.ParameterService;
028import org.kuali.rice.krad.util.GlobalVariables;
029import org.kuali.rice.krad.util.ObjectUtils;
030
031/**
032 * Validation that checks Budget Adjustment accounting lines to make sure that non-zero adjustments have related income stream accounts.
033 */
034public class BudgetAdjustmentAccountingLineAccountIncomeStreamValidation extends GenericValidation {
035    private BudgetAdjustmentAccountingLine accountingLineForValidation;
036
037    /**
038     * Validate that, if current adjustment amount is non zero, account has an associated income stream chart and account
039     * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
040     */
041    public boolean validate(AttributedDocumentEvent event) {
042        boolean accountNumberAllowed = true;
043        if (getAccountingLineForValidation().getCurrentBudgetAdjustmentAmount().isNonZero()) {
044            getAccountingLineForValidation().refreshReferenceObject("account");
045            
046            if (!ObjectUtils.isNull(getAccountingLineForValidation().getAccount())) {
047                //KFSMI-4877: if fund group is in system parameter values then income stream account number must exist.
048                String fundGroupCode = getAccountingLineForValidation().getAccount().getSubFundGroup().getFundGroupCode();
049                String incomeStreamRequiringFundGroupCode = SpringContext.getBean(ParameterService.class).getParameterValueAsString(Account.class, OLEConstants.ChartApcParms.INCOME_STREAM_ACCOUNT_REQUIRING_FUND_GROUPS);
050                if (StringUtils.containsIgnoreCase(fundGroupCode, incomeStreamRequiringFundGroupCode)) {
051                    if (ObjectUtils.isNull(getAccountingLineForValidation().getAccount().getIncomeStreamAccount())) {
052                        GlobalVariables.getMessageMap().putError(OLEPropertyConstants.ACCOUNT_NUMBER, OLEKeyConstants.ERROR_DOCUMENT_BA_NO_INCOME_STREAM_ACCOUNT, getAccountingLineForValidation().getAccountNumber());
053                        accountNumberAllowed = false;
054                    }
055                }
056            }
057        }
058        
059        return accountNumberAllowed;
060    }
061
062    /**
063     * Gets the accountingLineForValidation attribute. 
064     * @return Returns the accountingLineForValidation.
065     */
066    public BudgetAdjustmentAccountingLine getAccountingLineForValidation() {
067        return accountingLineForValidation;
068    }
069
070    /**
071     * Sets the accountingLineForValidation attribute value.
072     * @param accountingLineForValidation The accountingLineForValidation to set.
073     */
074    public void setAccountingLineForValidation(BudgetAdjustmentAccountingLine accountingLineForValidation) {
075        this.accountingLineForValidation = accountingLineForValidation;
076    }
077}