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.IndirectCostRecoveryExclusionAccount;
21 import org.kuali.rice.kns.document.MaintenanceDocument;
22 import org.kuali.rice.krad.util.ObjectUtils;
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 MaintenancePreRulesBase {
29
30 protected IndirectCostRecoveryExclusionAccount indirectCostRecoveryExclusionAccount;
31
32
33 public IndirectCostRecoveryExclusionAccountPreRules() {
34
35 }
36
37 /**
38 * This sets up the convenience objects and calls
39 * {@link IndirectCostRecoveryExclusionAccountPreRules#checkForContinuationAccounts()}
40 *
41 * @see org.kuali.ole.coa.document.validation.impl.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument)
42 */
43 protected boolean doCustomPreRules(MaintenanceDocument document) {
44 setupConvenienceObjects(document);
45 checkForContinuationAccounts(); // run this first to avoid side effects
46
47 LOG.debug("done with continuation account, proceeeding with remaining pre rules");
48
49
50 return true;
51 }
52
53 /**
54 * This method checks for continuation accounts and presents the user with a question regarding their use on this account.
55 */
56 protected void checkForContinuationAccounts() {
57 LOG.debug("entering checkForContinuationAccounts()");
58
59 if (StringUtils.isNotBlank(indirectCostRecoveryExclusionAccount.getAccountNumber())) {
60 Account account = checkForContinuationAccount("Account Number", indirectCostRecoveryExclusionAccount.getChartOfAccountsCode(), indirectCostRecoveryExclusionAccount.getAccountNumber(), "");
61 if (ObjectUtils.isNotNull(account)) { // override old user inputs
62 indirectCostRecoveryExclusionAccount.setAccountNumber(account.getAccountNumber());
63 indirectCostRecoveryExclusionAccount.setChartOfAccountsCode(account.getChartOfAccountsCode());
64 }
65 }
66 }
67
68 /**
69 * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
70 * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
71 * all sub-objects from the DB by their primary keys, if available.
72 *
73 * @param document - the maintenanceDocument being evaluated
74 */
75 protected void setupConvenienceObjects(MaintenanceDocument document) {
76
77 // setup newAccount convenience objects, make sure all possible sub-objects are populated
78 indirectCostRecoveryExclusionAccount = (IndirectCostRecoveryExclusionAccount) document.getNewMaintainableObject().getBusinessObject();
79 }
80 }