001/* 002 * Copyright 2006-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.coa.document.validation.impl; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.ole.coa.businessobject.Account; 020import org.kuali.ole.coa.businessobject.IndirectCostRecoveryRateDetail; 021import org.kuali.ole.sys.OLEConstants; 022import org.kuali.rice.kns.document.MaintenanceDocument; 023import org.kuali.rice.krad.util.ObjectUtils; 024 025/** 026 * PreRules checks for the {@link IndirectCostRecoveryRateDetail} that needs to occur while still in the Struts processing. This includes 027 * defaults, confirmations, etc. 028 */ 029public class IndirectCostRecoveryRateDetailPreRules extends MaintenancePreRulesBase { 030 031 032 protected IndirectCostRecoveryRateDetail indirectCostRecoveryRateDetail; 033 034 035 public IndirectCostRecoveryRateDetailPreRules() { 036 037 } 038 039 /** 040 * Executes the following pre rules 041 * <ul> 042 * <li>{@link IndirectCostRecoveryRateDetailPreRules#setSubAccountToDashesIfBlank()}</li> 043 * <li>{@link IndirectCostRecoveryRateDetailPreRules#setSubObjectToDashesIfBlank()}</li> 044 * </ul> 045 * 046 * @see org.kuali.module.chart.rules.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument) 047 */ 048 protected boolean doCustomPreRules(MaintenanceDocument document) { 049 setupConvenienceObjects(document); 050 checkForContinuationAccounts(); // run this first to avoid side effects 051 052 LOG.debug("done with continuation account, proceeeding with remaining pre rules"); 053 054 setSubAccountToDashesIfBlank(); 055 setSubObjectToDashesIfBlank(); 056 057 return true; 058 } 059 060 /** 061 * This method checks for continuation accounts and presents the user with a question regarding their use on this account. 062 */ 063 protected void checkForContinuationAccounts() { 064 LOG.debug("entering checkForContinuationAccounts()"); 065 066 if (StringUtils.isNotBlank(indirectCostRecoveryRateDetail.getAccountNumber())) { 067 Account account = checkForContinuationAccount("Account Number", indirectCostRecoveryRateDetail.getChartOfAccountsCode(), indirectCostRecoveryRateDetail.getAccountNumber(), ""); 068 if (ObjectUtils.isNotNull(account)) { // override old user inputs 069 indirectCostRecoveryRateDetail.setAccountNumber(account.getAccountNumber()); 070 indirectCostRecoveryRateDetail.setChartOfAccountsCode(account.getChartOfAccountsCode()); 071 } 072 } 073 } 074 075 /** 076 * This sets the {@link SubAccount} number to padded dashes ("-") if blank 077 */ 078 protected void setSubAccountToDashesIfBlank() { 079 String newSubAccount = indirectCostRecoveryRateDetail.getSubAccountNumber(); 080 if (StringUtils.isBlank(newSubAccount)) { 081 indirectCostRecoveryRateDetail.setSubAccountNumber(OLEConstants.getDashSubAccountNumber()); 082 } 083 } 084 085 /** 086 * This sets the {@link org.kuali.module.chart.bo.SubObjCd} code to padded dashes ("-") if blank 087 */ 088 protected void setSubObjectToDashesIfBlank() { 089 String newSubObject = indirectCostRecoveryRateDetail.getFinancialSubObjectCode(); 090 if (StringUtils.isBlank(newSubObject)) { 091 indirectCostRecoveryRateDetail.setFinancialSubObjectCode(OLEConstants.getDashFinancialSubObjectCode()); 092 } 093 } 094 095 /** 096 * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and 097 * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load 098 * all sub-objects from the DB by their primary keys, if available. 099 */ 100 protected void setupConvenienceObjects(MaintenanceDocument document) { 101 102 // setup newAccount convenience objects, make sure all possible sub-objects are populated 103 indirectCostRecoveryRateDetail = (IndirectCostRecoveryRateDetail) document.getNewMaintainableObject().getBusinessObject(); 104 } 105}