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.coa.document.validation.impl;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.kfs.coa.businessobject.Account;
020    import org.kuali.kfs.coa.businessobject.IndirectCostRecoveryExclusionAccount;
021    import org.kuali.rice.kns.document.MaintenanceDocument;
022    import org.kuali.rice.kns.util.ObjectUtils;
023    
024    /**
025     * PreRules checks for the {@link IndirectCostRecoveryExclusionAccount} that needs to occur while still in the Struts processing.
026     * This checks for continuation accounts
027     */
028    public class IndirectCostRecoveryExclusionAccountPreRules extends MaintenancePreRulesBase {
029    
030        protected IndirectCostRecoveryExclusionAccount indirectCostRecoveryExclusionAccount;
031    
032    
033        public IndirectCostRecoveryExclusionAccountPreRules() {
034    
035        }
036    
037        /**
038         * This sets up the convenience objects and calls
039         * {@link IndirectCostRecoveryExclusionAccountPreRules#checkForContinuationAccounts()}
040         * 
041         * @see org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument)
042         */
043        protected boolean doCustomPreRules(MaintenanceDocument document) {
044            setupConvenienceObjects(document);
045            checkForContinuationAccounts(); // run this first to avoid side effects
046    
047            LOG.debug("done with continuation account, proceeeding with remaining pre rules");
048    
049    
050            return true;
051        }
052    
053        /**
054         * This method checks for continuation accounts and presents the user with a question regarding their use on this account.
055         */
056        protected void checkForContinuationAccounts() {
057            LOG.debug("entering checkForContinuationAccounts()");
058    
059            if (StringUtils.isNotBlank(indirectCostRecoveryExclusionAccount.getAccountNumber())) {
060                Account account = checkForContinuationAccount("Account Number", indirectCostRecoveryExclusionAccount.getChartOfAccountsCode(), indirectCostRecoveryExclusionAccount.getAccountNumber(), "");
061                if (ObjectUtils.isNotNull(account)) { // override old user inputs
062                    indirectCostRecoveryExclusionAccount.setAccountNumber(account.getAccountNumber());
063                    indirectCostRecoveryExclusionAccount.setChartOfAccountsCode(account.getChartOfAccountsCode());
064                }
065            }
066        }
067    
068        /**
069         * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
070         * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
071         * all sub-objects from the DB by their primary keys, if available.
072         * 
073         * @param document - the maintenanceDocument being evaluated
074         */
075        protected void setupConvenienceObjects(MaintenanceDocument document) {
076    
077            // setup newAccount convenience objects, make sure all possible sub-objects are populated
078            indirectCostRecoveryExclusionAccount = (IndirectCostRecoveryExclusionAccount) document.getNewMaintainableObject().getBusinessObject();
079        }
080    }