001: /*
002: * Copyright 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.module.chart.bo.Account;
022: import org.kuali.module.chart.bo.OrganizationReversionGlobal;
023: import org.kuali.module.chart.bo.OrganizationReversionGlobalDetail;
024: import org.kuali.module.chart.bo.OrganizationReversionGlobalOrganization;
025:
026: /**
027: *
028: * PreRules checks for the {@link OrganizationReversionGlobal} that needs to occur while still in the Struts processing. This includes defaults
029: */
030: public class OrganizationReversionGlobalPreRules extends
031: MaintenancePreRulesBase {
032: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
033: .getLogger(OrganizationReversionGlobalPreRules.class);
034:
035: /**
036: * This is the hook method for the {@link MaintenancePreRulesBase} to call. It calls
037: * <ul>
038: * <li>{@link OrganizationReversionGlobalPreRules#checkForContinuationAccounts(OrganizationReversionGlobal)}</li>
039: * <li>{@link OrganizationReversionGlobalPreRules#copyKeyAttributesToCollections(OrganizationReversionGlobal)}</li>
040: * </ul>
041: * @see org.kuali.module.chart.rules.MaintenancePreRulesBase#doCustomPreRules(org.kuali.core.document.MaintenanceDocument)
042: */
043: @Override
044: public boolean doCustomPreRules(
045: MaintenanceDocument maintenanceDocument) {
046: OrganizationReversionGlobal globalOrgReversion = (OrganizationReversionGlobal) maintenanceDocument
047: .getNewMaintainableObject().getBusinessObject();
048: checkForContinuationAccounts(globalOrgReversion);
049: copyKeyAttributesToCollections(globalOrgReversion);
050: return true;
051: }
052:
053: /**
054: * This method checks to see if the budget reversion or cash reversion accounts have continuation accounts.
055: *
056: * @param globalOrgReversion Global Organization Reversion to check.
057: */
058: public void checkForContinuationAccounts(
059: OrganizationReversionGlobal globalOrgReversion) {
060: if (!StringUtils.isBlank(globalOrgReversion
061: .getBudgetReversionChartOfAccountsCode())
062: && !StringUtils.isBlank(globalOrgReversion
063: .getBudgetReversionAccountNumber())) {
064: Account account = checkForContinuationAccount(
065: "Budget Reversion Account Number",
066: globalOrgReversion
067: .getBudgetReversionChartOfAccountsCode(),
068: globalOrgReversion
069: .getBudgetReversionAccountNumber(), "");
070: if (ObjectUtils.isNotNull(account)) {
071: globalOrgReversion
072: .setBudgetReversionChartOfAccountsCode(account
073: .getChartOfAccountsCode());
074: globalOrgReversion
075: .setBudgetReversionAccountNumber(account
076: .getAccountNumber());
077: }
078: }
079: if (!StringUtils.isBlank(globalOrgReversion
080: .getCashReversionFinancialChartOfAccountsCode())
081: && !StringUtils.isBlank(globalOrgReversion
082: .getBudgetReversionAccountNumber())) {
083: Account account = checkForContinuationAccount(
084: "Cash Reversion Account Number",
085: globalOrgReversion
086: .getCashReversionFinancialChartOfAccountsCode(),
087: globalOrgReversion.getCashReversionAccountNumber(),
088: "");
089: if (ObjectUtils.isNotNull(account)) {
090: globalOrgReversion
091: .setCashReversionFinancialChartOfAccountsCode(account
092: .getChartOfAccountsCode());
093: globalOrgReversion
094: .setCashReversionAccountNumber(account
095: .getAccountNumber());
096: }
097: }
098: }
099:
100: /**
101: * This method updates all children of a Global Organization Reversion so that they all are associated with the Global
102: * Organization Reversion document, by upudating their primary keys.
103: *
104: * @param globalOrgRev the global organization reversion document to update.
105: */
106: public void copyKeyAttributesToCollections(
107: OrganizationReversionGlobal globalOrgRev) {
108: for (OrganizationReversionGlobalDetail orgRevDetail : globalOrgRev
109: .getOrganizationReversionGlobalDetails()) {
110: orgRevDetail.setDocumentNumber(globalOrgRev
111: .getDocumentNumber());
112: }
113:
114: for (OrganizationReversionGlobalOrganization orgRevOrg : globalOrgRev
115: .getOrganizationReversionGlobalOrganizations()) {
116: orgRevOrg.setDocumentNumber(globalOrgRev
117: .getDocumentNumber());
118: }
119: }
120:
121: }
|