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.SubObjCd;
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: private SubObjCd newSubObjectCode;
30: private SubObjCd copySubObjectCode;
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.module.chart.rules.MaintenancePreRulesBase#doCustomPreRules(org.kuali.core.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
50: .debug("done with continuation account, proceeeding with remaining pre rules");
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: private void checkForContinuationAccounts() {
60: LOG.debug("entering checkForContinuationAccounts()");
61:
62: if (StringUtils.isNotBlank(newSubObjectCode.getAccountNumber())) {
63: Account account = checkForContinuationAccount(
64: "Account Number", newSubObjectCode
65: .getChartOfAccountsCode(), newSubObjectCode
66: .getAccountNumber(), "");
67: if (ObjectUtils.isNotNull(account)) { // override old user inputs
68: newSubObjectCode.setAccountNumber(account
69: .getAccountNumber());
70: newSubObjectCode.setChartOfAccountsCode(account
71: .getChartOfAccountsCode());
72: }
73: }
74: }
75:
76: /**
77: * This method sets the convenience objects like newSubObjectCode and copySubObjectCode, so you have short and easy handles to the new and
78: * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
79: * all sub-objects from the DB by their primary keys, if available.
80: * @param document
81: */
82: private void setupConvenienceObjects(MaintenanceDocument document) {
83:
84: // setup newAccount convenience objects, make sure all possible sub-objects are populated
85: newSubObjectCode = (SubObjCd) document
86: .getNewMaintainableObject().getBusinessObject();
87: copySubObjectCode = (SubObjCd) ObjectUtils
88: .deepCopy(newSubObjectCode);
89: copySubObjectCode.refresh();
90: }
91: }
|