View Javadoc
1   /*
2    * Copyright 2006 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.SubObjectCode;
21  import org.kuali.rice.kns.document.MaintenanceDocument;
22  import org.kuali.rice.krad.util.ObjectUtils;
23  
24  /**
25   * PreRules checks for the {@link SubObjCd} that needs to occur while still in the Struts processing. This includes defaults, confirmations,
26   * etc.
27   */
28  public class SubObjectPreRules extends MaintenancePreRulesBase {
29      protected SubObjectCode newSubObjectCode;
30  
31  
32      public SubObjectPreRules() {
33  
34      }
35      
36      /**
37       * Executes the following pre rules
38       * <ul>
39       * <li>{@link SubObjectPreRules#checkForContinuationAccounts()}</li>
40       * </ul>
41       * This does not fail on rule failures
42       * @see org.kuali.ole.coa.document.validation.impl.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument)
43       */
44      protected boolean doCustomPreRules(MaintenanceDocument document) {
45  
46          setupConvenienceObjects(document);
47          checkForContinuationAccounts(); // run this first to avoid side effects
48  
49          LOG.debug("done with continuation account, proceeeding with remaining pre rules");
50  
51  
52          return true;
53      }
54  
55      /**
56       * This method checks for continuation accounts and presents the user with a question regarding their use on this account.
57       * 
58       */
59      protected void checkForContinuationAccounts() {
60          LOG.debug("entering checkForContinuationAccounts()");
61  
62          if (StringUtils.isNotBlank(newSubObjectCode.getAccountNumber())) {
63              Account account = checkForContinuationAccount("Account Number", newSubObjectCode.getChartOfAccountsCode(), newSubObjectCode.getAccountNumber(), "");
64              if (ObjectUtils.isNotNull(account)) { // override old user inputs
65                  newSubObjectCode.setAccountNumber(account.getAccountNumber());
66                  newSubObjectCode.setChartOfAccountsCode(account.getChartOfAccountsCode());
67              }
68          }
69      }
70  
71      /**
72       * This method sets the convenience objects like newSubObjectCode and copySubObjectCode, so you have short and easy handles to the new and
73       * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
74       * all sub-objects from the DB by their primary keys, if available.
75       * @param document
76       */
77      protected void setupConvenienceObjects(MaintenanceDocument document) {
78  
79          // setup newAccount convenience objects, make sure all possible sub-objects are populated
80          newSubObjectCode = (SubObjectCode) document.getNewMaintainableObject().getBusinessObject();
81      }
82  }