01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.chart.rules;
17:
18: import org.apache.commons.lang.StringUtils;
19: import org.kuali.core.document.MaintenanceDocument;
20: import org.kuali.core.util.ObjectUtils;
21: import org.kuali.module.chart.bo.Account;
22: import org.kuali.module.chart.bo.IndirectCostRecoveryExclusionAccount;
23:
24: /**
25: * PreRules checks for the {@link IndirectCostRecoveryExclusionAccount} that needs to occur while still in the Struts processing.
26: * This checks for continuation accounts
27: */
28: public class IndirectCostRecoveryExclusionAccountPreRules extends
29: MaintenancePreRulesBase {
30:
31: private IndirectCostRecoveryExclusionAccount newAccount;
32: private IndirectCostRecoveryExclusionAccount copyAccount;
33:
34: public IndirectCostRecoveryExclusionAccountPreRules() {
35:
36: }
37:
38: /**
39: * This sets up the convenience objects and calls
40: * {@link IndirectCostRecoveryExclusionAccountPreRules#checkForContinuationAccounts()}
41: *
42: * @see org.kuali.module.chart.rules.MaintenancePreRulesBase#doCustomPreRules(org.kuali.core.document.MaintenanceDocument)
43: */
44: protected boolean doCustomPreRules(MaintenanceDocument document) {
45: setupConvenienceObjects(document);
46: checkForContinuationAccounts(); // run this first to avoid side effects
47:
48: LOG
49: .debug("done with continuation account, proceeeding with remaining pre rules");
50:
51: return true;
52: }
53:
54: /**
55: * This method checks for continuation accounts and presents the user with a question regarding their use on this account.
56: */
57: private void checkForContinuationAccounts() {
58: LOG.debug("entering checkForContinuationAccounts()");
59:
60: if (StringUtils.isNotBlank(newAccount.getAccountNumber())) {
61: Account account = checkForContinuationAccount(
62: "Account Number", newAccount
63: .getChartOfAccountsCode(), newAccount
64: .getAccountNumber(), "");
65: if (ObjectUtils.isNotNull(account)) { // override old user inputs
66: newAccount.setAccountNumber(account.getAccountNumber());
67: newAccount.setChartOfAccountsCode(account
68: .getChartOfAccountsCode());
69: }
70: }
71: }
72:
73: /**
74: * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
75: * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
76: * all sub-objects from the DB by their primary keys, if available.
77: *
78: * @param document - the maintenanceDocument being evaluated
79: */
80: private void setupConvenienceObjects(MaintenanceDocument document) {
81:
82: // setup newAccount convenience objects, make sure all possible sub-objects are populated
83: newAccount = (IndirectCostRecoveryExclusionAccount) document
84: .getNewMaintainableObject().getBusinessObject();
85: copyAccount = (IndirectCostRecoveryExclusionAccount) ObjectUtils
86: .deepCopy(newAccount);
87: copyAccount.refresh();
88: }
89: }
|