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.coa.businessobject.Account;
020 import org.kuali.kfs.fp.businessobject.BudgetAdjustmentAccountingLine;
021 import org.kuali.kfs.sys.KFSConstants;
022 import org.kuali.kfs.sys.KFSKeyConstants;
023 import org.kuali.kfs.sys.KFSPropertyConstants;
024 import org.kuali.kfs.sys.context.SpringContext;
025 import org.kuali.kfs.sys.document.validation.GenericValidation;
026 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
027 import org.kuali.rice.kns.service.ParameterService;
028 import org.kuali.rice.kns.util.GlobalVariables;
029 import org.kuali.rice.kns.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 */
034 public 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.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.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).getParameterValue(Account.class, KFSConstants.ChartApcParms.INCOME_STREAM_ACCOUNT_REQUIRING_FUND_GROUPS);
050 if (StringUtils.containsIgnoreCase(fundGroupCode, incomeStreamRequiringFundGroupCode)) {
051 if (ObjectUtils.isNull(getAccountingLineForValidation().getAccount().getIncomeStreamAccount())) {
052 GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ACCOUNT_NUMBER, KFSKeyConstants.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 }