View Javadoc
1   /*
2    * Copyright 2006-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.coa.document.validation.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.coa.businessobject.Account;
20  import org.kuali.ole.coa.businessobject.IndirectCostRecoveryRateDetail;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.rice.kns.document.MaintenanceDocument;
23  import org.kuali.rice.krad.util.ObjectUtils;
24  
25  /**
26   * PreRules checks for the {@link IndirectCostRecoveryRateDetail} that needs to occur while still in the Struts processing. This includes
27   * defaults, confirmations, etc.
28   */
29  public class IndirectCostRecoveryRateDetailPreRules extends MaintenancePreRulesBase {
30  
31  
32      protected IndirectCostRecoveryRateDetail indirectCostRecoveryRateDetail;
33  
34  
35      public IndirectCostRecoveryRateDetailPreRules() {
36  
37      }
38  
39      /**
40       * Executes the following pre rules
41       * <ul>
42       * <li>{@link IndirectCostRecoveryRateDetailPreRules#setSubAccountToDashesIfBlank()}</li>
43       * <li>{@link IndirectCostRecoveryRateDetailPreRules#setSubObjectToDashesIfBlank()}</li>
44       * </ul>
45       * 
46       * @see org.kuali.module.chart.rules.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument)
47       */
48      protected boolean doCustomPreRules(MaintenanceDocument document) {
49          setupConvenienceObjects(document);
50          checkForContinuationAccounts(); // run this first to avoid side effects
51  
52          LOG.debug("done with continuation account, proceeeding with remaining pre rules");
53  
54          setSubAccountToDashesIfBlank();
55          setSubObjectToDashesIfBlank();
56  
57          return true;
58      }
59  
60      /**
61       * This method checks for continuation accounts and presents the user with a question regarding their use on this account.
62       */
63      protected void checkForContinuationAccounts() {
64          LOG.debug("entering checkForContinuationAccounts()");
65  
66          if (StringUtils.isNotBlank(indirectCostRecoveryRateDetail.getAccountNumber())) {
67              Account account = checkForContinuationAccount("Account Number", indirectCostRecoveryRateDetail.getChartOfAccountsCode(), indirectCostRecoveryRateDetail.getAccountNumber(), "");
68              if (ObjectUtils.isNotNull(account)) { // override old user inputs
69                  indirectCostRecoveryRateDetail.setAccountNumber(account.getAccountNumber());
70                  indirectCostRecoveryRateDetail.setChartOfAccountsCode(account.getChartOfAccountsCode());
71              }
72          }
73      }
74  
75      /**
76       * This sets the {@link SubAccount} number to padded dashes ("-") if blank
77       */
78      protected void setSubAccountToDashesIfBlank() {
79          String newSubAccount = indirectCostRecoveryRateDetail.getSubAccountNumber();
80          if (StringUtils.isBlank(newSubAccount)) {
81              indirectCostRecoveryRateDetail.setSubAccountNumber(OLEConstants.getDashSubAccountNumber());
82          }
83      }
84  
85      /**
86       * This sets the {@link org.kuali.module.chart.bo.SubObjCd} code to padded dashes ("-") if blank
87       */
88      protected void setSubObjectToDashesIfBlank() {
89          String newSubObject = indirectCostRecoveryRateDetail.getFinancialSubObjectCode();
90          if (StringUtils.isBlank(newSubObject)) {
91              indirectCostRecoveryRateDetail.setFinancialSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
92          }
93      }
94  
95      /**
96       * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
97       * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
98       * all sub-objects from the DB by their primary keys, if available.
99       */
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 }