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 import org.kuali.rice.kns.util.ObjectUtils; 027 028 /** 029 * This class... 030 */ 031 public class IndirectCostAdjustmentAccountValidation extends GenericValidation { 032 private AccountingLine accountingLineForValidation; 033 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(IndirectCostAdjustmentAccountValidation.class); 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 AccountingLine accountingLine = getAccountingLineForValidation(); 039 boolean isValid = true; 040 if (isValid && accountingLine.isSourceAccountingLine()) { 041 accountingLine.refreshReferenceObject("account"); 042 if (!ObjectUtils.isNull(accountingLine.getAccount())) { 043 String icrAccount = accountingLine.getAccount().getIndirectCostRecoveryAcctNbr(); 044 isValid &= StringUtils.isNotBlank(icrAccount); 045 if (!isValid) { 046 reportError(KFSPropertyConstants.ACCOUNT, KFSKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_GRANT_INVALID_ACCOUNT, accountingLine.getAccountNumber()); 047 } 048 } 049 } 050 return isValid; 051 } 052 053 /** 054 * Gets the accountingLineForValidation attribute. 055 * @return Returns the accountingLineForValidation. 056 */ 057 public AccountingLine getAccountingLineForValidation() { 058 return accountingLineForValidation; 059 } 060 061 /** 062 * Sets the accountingLineForValidation attribute value. 063 * @param accountingLineForValidation The accountingLineForValidation to set. 064 */ 065 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) { 066 this.accountingLineForValidation = accountingLineForValidation; 067 } 068 069 /** 070 * Wrapper around global errorMap.put call, to allow better logging 071 * 072 * @param propertyName 073 * @param errorKey 074 * @param errorParams 075 */ 076 protected void reportError(String propertyName, String errorKey, String... errorParams) { 077 LOG.debug("reportError(String, String, String) - start"); 078 079 GlobalVariables.getMessageMap().putError(propertyName, errorKey, errorParams); 080 if (LOG.isDebugEnabled()) { 081 LOG.debug("rule failure at " + ExceptionUtils.describeStackLevels(1, 2)); 082 } 083 } 084 085 }