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.sys.KFSKeyConstants; 020 import org.kuali.kfs.sys.KFSPropertyConstants; 021 import org.kuali.kfs.sys.businessobject.AccountingLine; 022 import org.kuali.kfs.sys.document.validation.GenericValidation; 023 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 024 import org.kuali.rice.kns.util.ExceptionUtils; 025 import org.kuali.rice.kns.util.GlobalVariables; 026 027 /** 028 * This class... 029 */ 030 public class IndirectCostAdjustmentChartOfAccountsValidation extends GenericValidation { 031 private AccountingLine accountingLineForValidation; 032 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(IndirectCostAdjustmentChartOfAccountsValidation.class); 033 /** 034 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent) 035 */ 036 public boolean validate(AttributedDocumentEvent event) { 037 boolean isValid = true; 038 AccountingLine accountingLine = getAccountingLineForValidation(); 039 040 if (accountingLine.isSourceAccountingLine()) { 041 String icrExpense = accountingLine.getChart().getIcrExpenseFinancialObjectCd(); 042 isValid &= StringUtils.isNotBlank(icrExpense); 043 if (!isValid) { 044 reportError(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_GRANT_INVALID_CHART_OF_ACCOUNTS, new String[] { accountingLine.getChartOfAccountsCode() }); 045 } 046 } 047 else { 048 String icrIncome = accountingLine.getChart().getIcrIncomeFinancialObjectCode(); 049 isValid &= StringUtils.isNotBlank(icrIncome); 050 if (!isValid) { 051 reportError(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_RECEIPT_INVALID_CHART_OF_ACCOUNTS, new String[] { accountingLine.getChartOfAccountsCode() }); 052 } 053 } 054 055 return isValid; 056 } 057 058 /** 059 * Gets the accountingLineForValidation attribute. 060 * @return Returns the accountingLineForValidation. 061 */ 062 public AccountingLine getAccountingLineForValidation() { 063 return accountingLineForValidation; 064 } 065 066 /** 067 * Sets the accountingLineForValidation attribute value. 068 * @param accountingLineForValidation The accountingLineForValidation to set. 069 */ 070 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) { 071 this.accountingLineForValidation = accountingLineForValidation; 072 } 073 074 075 /** 076 * Wrapper around global errorMap.put call, to allow better logging 077 * 078 * @param propertyName 079 * @param errorKey 080 * @param errorParams 081 */ 082 protected void reportError(String propertyName, String errorKey, String... errorParams) { 083 LOG.debug("reportError(String, String, String) - start"); 084 085 GlobalVariables.getMessageMap().putError(propertyName, errorKey, errorParams); 086 if (LOG.isDebugEnabled()) { 087 LOG.debug("rule failure at " + ExceptionUtils.describeStackLevels(1, 2)); 088 } 089 } 090 091 }