001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.chart.rules;
017:
018: import org.apache.commons.lang.StringUtils;
019: import org.kuali.core.document.MaintenanceDocument;
020: import org.kuali.core.util.ObjectUtils;
021: import org.kuali.kfs.KFSConstants;
022: import org.kuali.module.chart.bo.Account;
023: import org.kuali.module.chart.bo.IcrAutomatedEntry;
024:
025: /**
026: * PreRules checks for the {@link IcrAutomatedEntry} that needs to occur while still in the Struts processing. This includes
027: * defaults, confirmations, etc.
028: */
029: public class IcrAutomatedEntryPreRules extends MaintenancePreRulesBase {
030:
031: private IcrAutomatedEntry newAccount;
032: private IcrAutomatedEntry copyAccount;
033:
034: public IcrAutomatedEntryPreRules() {
035:
036: }
037:
038: /**
039: * Executes the following pre rules
040: * <ul>
041: * <li>{@link IcrAutomatedEntryPreRules#setSubAccountToDashesIfBlank()}</li>
042: * <li>{@link IcrAutomatedEntryPreRules#setSubObjectToDashesIfBlank()}</li>
043: * </ul>
044: *
045: * @see org.kuali.module.chart.rules.MaintenancePreRulesBase#doCustomPreRules(org.kuali.core.document.MaintenanceDocument)
046: */
047: protected boolean doCustomPreRules(MaintenanceDocument document) {
048: setupConvenienceObjects(document);
049: checkForContinuationAccounts(); // run this first to avoid side effects
050:
051: LOG
052: .debug("done with continuation account, proceeeding with remaining pre rules");
053:
054: setSubAccountToDashesIfBlank();
055: setSubObjectToDashesIfBlank();
056:
057: return true;
058: }
059:
060: /**
061: * This method checks for continuation accounts and presents the user with a question regarding their use on this account.
062: */
063: private void checkForContinuationAccounts() {
064: LOG.debug("entering checkForContinuationAccounts()");
065:
066: if (StringUtils.isNotBlank(newAccount.getAccountNumber())) {
067: Account account = checkForContinuationAccount(
068: "Account Number", newAccount
069: .getChartOfAccountsCode(), newAccount
070: .getAccountNumber(), "");
071: if (ObjectUtils.isNotNull(account)) { // override old user inputs
072: newAccount.setAccountNumber(account.getAccountNumber());
073: newAccount.setChartOfAccountsCode(account
074: .getChartOfAccountsCode());
075: }
076: }
077: }
078:
079: /**
080: * This sets the {@link SubAccount} number to padded dashes ("-") if blank
081: */
082: protected void setSubAccountToDashesIfBlank() {
083: String newSubAccount = newAccount.getSubAccountNumber();
084: if (StringUtils.isBlank(newSubAccount)) {
085: newAccount.setSubAccountNumber(KFSConstants
086: .getDashSubAccountNumber());
087: }
088: }
089:
090: /**
091: * This sets the {@link org.kuali.module.chart.bo.SubObjCd} code to padded dashes ("-") if blank
092: */
093: protected void setSubObjectToDashesIfBlank() {
094: String newSubObject = newAccount.getFinancialSubObjectCode();
095: if (StringUtils.isBlank(newSubObject)) {
096: newAccount.setFinancialSubObjectCode(KFSConstants
097: .getDashFinancialSubObjectCode());
098: }
099: }
100:
101: /**
102: * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
103: * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
104: * all sub-objects from the DB by their primary keys, if available.
105: */
106: private void setupConvenienceObjects(MaintenanceDocument document) {
107:
108: // setup newAccount convenience objects, make sure all possible sub-objects are populated
109: newAccount = (IcrAutomatedEntry) document
110: .getNewMaintainableObject().getBusinessObject();
111: copyAccount = (IcrAutomatedEntry) ObjectUtils
112: .deepCopy(newAccount);
113: copyAccount.refresh();
114: }
115: }
|