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.bo.user.UniversalUser;
020: import org.kuali.core.document.MaintenanceDocument;
021: import org.kuali.core.document.authorization.MaintenanceDocumentAuthorizations;
022: import org.kuali.core.document.authorization.MaintenanceDocumentAuthorizer;
023: import org.kuali.core.util.GlobalVariables;
024: import org.kuali.core.util.ObjectUtils;
025: import org.kuali.kfs.KFSConstants;
026: import org.kuali.module.chart.bo.A21SubAccount;
027: import org.kuali.module.chart.bo.Account;
028: import org.kuali.module.chart.bo.SubAccount;
029:
030: /**
031: * PreRules checks for the {@link SubAccount} that needs to occur while still in the Struts processing. This includes defaults, confirmations,
032: * etc.
033: */
034: public class SubAccountPreRules extends MaintenancePreRulesBase {
035:
036: private SubAccount newSubAccount;
037:
038: // private SubAccount copyAccount;
039:
040: public SubAccountPreRules() {
041:
042: }
043:
044: /**
045: * This checks to see if a continuation account is necessary and then copies the ICR data from the Account
046: * associated with this SubAccount (if necessary)
047: * @see org.kuali.module.chart.rules.MaintenancePreRulesBase#doCustomPreRules(org.kuali.core.document.MaintenanceDocument)
048: */
049: protected boolean doCustomPreRules(MaintenanceDocument document) {
050: setupConvenienceObjects(document);
051: checkForContinuationAccounts(document
052: .getNewMaintainableObject().getMaintenanceAction()); // run this first to avoid side
053: // effects
054:
055: LOG
056: .debug("done with continuation account, proceeeding with remaining pre rules");
057:
058: copyICRFromAccount(document);
059:
060: return true;
061: }
062:
063: /**
064: *
065: * This looks for the SubAccount's account number and then sets the values to the continuation account value if it exists
066: * @param maintenanceAction
067: */
068: private void checkForContinuationAccounts(String maintenanceAction) {
069: LOG.debug("entering checkForContinuationAccounts()");
070:
071: /*
072: * KULCOA-734 - The check for continuation account for main Account Number on sub-account has been modified to only occur
073: * for a New and Copy Action. This cannot happen on an Edit as the primary key will change.
074: */
075: if (KFSConstants.MAINTENANCE_NEW_ACTION
076: .equals(maintenanceAction)
077: || KFSConstants.MAINTENANCE_COPY_ACTION
078: .equals(maintenanceAction)) {
079:
080: if (StringUtils
081: .isNotBlank(newSubAccount.getAccountNumber())) {
082: Account account = checkForContinuationAccount(
083: "Account Number", newSubAccount
084: .getChartOfAccountsCode(),
085: newSubAccount.getAccountNumber(), "");
086: if (ObjectUtils.isNotNull(account)) { // override old user inputs
087: newSubAccount.setAccountNumber(account
088: .getAccountNumber());
089: newSubAccount.setChartOfAccountsCode(account
090: .getChartOfAccountsCode());
091: }
092: }
093: }
094: }
095:
096: /**
097: * This method sets the convenience objects like newSubAccount, so you have short and easy handles to the new and
098: * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
099: * all sub-objects from the DB by their primary keys, if available.
100: * @param document
101: */
102: private void setupConvenienceObjects(MaintenanceDocument document) {
103:
104: // setup newAccount convenience objects, make sure all possible sub-objects are populated
105: newSubAccount = (SubAccount) document
106: .getNewMaintainableObject().getBusinessObject();
107: // copyAccount = (SubAccount) ObjectUtils.deepCopy(newAccount);
108: // copyAccount.refresh();
109: }
110:
111: /**
112: *
113: * This copies the Indirect Cost Rate (ICR) from the account if the SubAccount is a specific type - determined
114: * as "EX" from {@link SubAccountRule#CG_A21_TYPE_ICR}
115: * <p>
116: * If it is "EX" it will then copy over the ICR information from the Account specified for this SubAccount
117: * @param document
118: */
119: private void copyICRFromAccount(MaintenanceDocument document) {
120: UniversalUser user = GlobalVariables.getUserSession()
121: .getUniversalUser();
122:
123: // get the correct documentAuthorizer for this document
124: MaintenanceDocumentAuthorizer documentAuthorizer = (MaintenanceDocumentAuthorizer) getDocumentAuthorizationService()
125: .getDocumentAuthorizer(document);
126:
127: // get a new instance of MaintenanceDocumentAuthorizations for this context
128: MaintenanceDocumentAuthorizations auths = documentAuthorizer
129: .getFieldAuthorizations(document, user);
130:
131: // don't need to copy if the user does not have the authority to edit the fields
132: if (!auths.getAuthFieldAuthorization(
133: "a21SubAccount.financialIcrSeriesIdentifier")
134: .isReadOnly()) {
135: // only need to do this of the account sub type is EX
136: A21SubAccount a21SubAccount = newSubAccount
137: .getA21SubAccount();
138: Account account = newSubAccount.getAccount();
139: if (SubAccountRule.CG_A21_TYPE_ICR.equals(a21SubAccount
140: .getSubAccountTypeCode())) {
141: if (account == null
142: || StringUtils.isBlank(account
143: .getAccountNumber())) {
144: account = getAccountService().getByPrimaryId(
145: newSubAccount.getChartOfAccountsCode(),
146: newSubAccount.getAccountNumber());
147: if (ObjectUtils.isNotNull(account)) {
148: if (StringUtils
149: .isBlank(a21SubAccount
150: .getIndirectCostRecoveryAccountNumber())) {
151: a21SubAccount
152: .setIndirectCostRecoveryAccountNumber(account
153: .getIndirectCostRecoveryAcctNbr());
154: a21SubAccount
155: .setIndirectCostRecoveryChartOfAccountsCode(account
156: .getIndirectCostRcvyFinCoaCode());
157: }
158: if (StringUtils.isBlank(a21SubAccount
159: .getFinancialIcrSeriesIdentifier())) {
160: a21SubAccount
161: .setFinancialIcrSeriesIdentifier(account
162: .getFinancialIcrSeriesIdentifier());
163: a21SubAccount.setOffCampusCode(account
164: .isAccountOffCampusIndicator());
165: }
166: if (StringUtils.isBlank(a21SubAccount
167: .getIndirectCostRecoveryTypeCode())) {
168: a21SubAccount
169: .setIndirectCostRecoveryTypeCode(account
170: .getAcctIndirectCostRcvyTypeCd());
171: }
172: }
173: }
174: }
175: }
176: }
177: }
|