View Javadoc
1   /*
2    * Copyright 2007 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.OrganizationReversionGlobal;
21  import org.kuali.ole.coa.businessobject.OrganizationReversionGlobalDetail;
22  import org.kuali.ole.coa.businessobject.OrganizationReversionGlobalOrganization;
23  import org.kuali.rice.kns.document.MaintenanceDocument;
24  import org.kuali.rice.krad.util.ObjectUtils;
25  
26  /**
27   * 
28   * PreRules checks for the {@link OrganizationReversionGlobal} that needs to occur while still in the Struts processing. This includes defaults
29   */
30  public class OrganizationReversionGlobalPreRules extends MaintenancePreRulesBase {
31      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionGlobalPreRules.class);
32  
33      /**
34       * This is the hook method for the {@link MaintenancePreRulesBase} to call. It calls
35       * <ul>
36       * <li>{@link OrganizationReversionGlobalPreRules#checkForContinuationAccounts(OrganizationReversionGlobal)}</li>
37       * <li>{@link OrganizationReversionGlobalPreRules#copyKeyAttributesToCollections(OrganizationReversionGlobal)}</li>
38       * </ul>
39       * @see org.kuali.ole.coa.document.validation.impl.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument)
40       */
41      @Override
42      public boolean doCustomPreRules(MaintenanceDocument maintenanceDocument) {
43          OrganizationReversionGlobal globalOrgReversion = (OrganizationReversionGlobal) maintenanceDocument.getNewMaintainableObject().getBusinessObject();
44          checkForContinuationAccounts(globalOrgReversion);
45          copyKeyAttributesToCollections(globalOrgReversion);
46          return true;
47      }
48  
49      /**
50       * This method checks to see if the budget reversion or cash reversion accounts have continuation accounts.
51       * 
52       * @param globalOrgReversion Global Organization Reversion to check.
53       */
54      public void checkForContinuationAccounts(OrganizationReversionGlobal globalOrgReversion) {
55          if (!StringUtils.isBlank(globalOrgReversion.getBudgetReversionChartOfAccountsCode()) && !StringUtils.isBlank(globalOrgReversion.getBudgetReversionAccountNumber())) {
56              Account account = checkForContinuationAccount("Budget Reversion Account Number", globalOrgReversion.getBudgetReversionChartOfAccountsCode(), globalOrgReversion.getBudgetReversionAccountNumber(), "");
57              if (ObjectUtils.isNotNull(account)) {
58                  globalOrgReversion.setBudgetReversionChartOfAccountsCode(account.getChartOfAccountsCode());
59                  globalOrgReversion.setBudgetReversionAccountNumber(account.getAccountNumber());
60              }
61          }
62          if (!StringUtils.isBlank(globalOrgReversion.getCashReversionFinancialChartOfAccountsCode()) && !StringUtils.isBlank(globalOrgReversion.getBudgetReversionAccountNumber())) {
63              Account account = checkForContinuationAccount("Cash Reversion Account Number", globalOrgReversion.getCashReversionFinancialChartOfAccountsCode(), globalOrgReversion.getCashReversionAccountNumber(), "");
64              if (ObjectUtils.isNotNull(account)) {
65                  globalOrgReversion.setCashReversionFinancialChartOfAccountsCode(account.getChartOfAccountsCode());
66                  globalOrgReversion.setCashReversionAccountNumber(account.getAccountNumber());
67              }
68          }
69      }
70  
71      /**
72       * This method updates all children of a Global Organization Reversion so that they all are associated with the Global
73       * Organization Reversion document, by upudating their primary keys.
74       * 
75       * @param globalOrgRev the global organization reversion document to update.
76       */
77      public void copyKeyAttributesToCollections(OrganizationReversionGlobal globalOrgRev) {
78          for (OrganizationReversionGlobalDetail orgRevDetail : globalOrgRev.getOrganizationReversionGlobalDetails()) {
79              orgRevDetail.setDocumentNumber(globalOrgRev.getDocumentNumber());
80          }
81  
82          for (OrganizationReversionGlobalOrganization orgRevOrg : globalOrgRev.getOrganizationReversionGlobalOrganizations()) {
83              orgRevOrg.setDocumentNumber(globalOrgRev.getDocumentNumber());
84          }
85      }
86  
87  }