View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.bc.document.validation.impl;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.List;
24  
25  import org.kuali.kfs.module.bc.BCConstants.MonthSpreadDeleteType;
26  import org.kuali.kfs.module.bc.BCConstants.SynchronizationCheckType;
27  import org.kuali.kfs.module.bc.businessobject.BudgetConstructionMonthly;
28  import org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding;
29  import org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionGeneralLedger;
30  import org.kuali.kfs.module.bc.document.BudgetConstructionDocument;
31  import org.kuali.kfs.module.bc.document.validation.AddBudgetConstructionDocumentRule;
32  import org.kuali.kfs.module.bc.document.validation.AddPendingBudgetGeneralLedgerLineRule;
33  import org.kuali.kfs.module.bc.document.validation.BudgetExpansionRule;
34  import org.kuali.kfs.module.bc.document.validation.DeleteMonthlySpreadRule;
35  import org.kuali.kfs.module.bc.document.validation.DeletePendingBudgetGeneralLedgerLineRule;
36  import org.kuali.kfs.module.bc.document.validation.SalarySettingRule;
37  import org.kuali.kfs.module.bc.document.validation.SaveMonthlyBudgetRule;
38  import org.kuali.kfs.module.bc.document.validation.event.BudgetExpansionEvent;
39  import org.kuali.rice.krad.document.Document;
40  import org.kuali.rice.krad.rules.rule.BusinessRule;
41  import org.kuali.rice.krad.rules.rule.SaveDocumentRule;
42  
43  /**
44   * Base rule class for Budget Construction. Handles calling other expansion rule classes and the core budget document rules.
45   */
46  public class BudgetConstructionRules implements BudgetExpansionRule, SalarySettingRule, SaveDocumentRule, AddBudgetConstructionDocumentRule<BudgetConstructionDocument>, AddPendingBudgetGeneralLedgerLineRule<BudgetConstructionDocument, PendingBudgetConstructionGeneralLedger>, DeletePendingBudgetGeneralLedgerLineRule<BudgetConstructionDocument, PendingBudgetConstructionGeneralLedger>, DeleteMonthlySpreadRule<BudgetConstructionDocument>, SaveMonthlyBudgetRule<BudgetConstructionDocument, BudgetConstructionMonthly> {
47      private Collection<BusinessRule> expansionRules;
48      private BudgetConstructionDocumentRules budgetConstructionDocumentRules;
49      private SalarySettingRule salarySettingRules;
50  
51      /**
52       * Initialize expansion rule classes.
53       */
54      public BudgetConstructionRules() {
55          expansionRules = new ArrayList<BusinessRule>();
56  
57          try {
58              budgetConstructionDocumentRules = BudgetConstructionDocumentRules.class.newInstance();
59              expansionRules.add(budgetConstructionDocumentRules);
60  
61              salarySettingRules = SalarySettingRules.class.newInstance();
62              expansionRules.add(salarySettingRules);
63          }
64          catch (InstantiationException e) {
65              throw new RuntimeException(e);
66          }
67          catch (IllegalAccessException e) {
68              throw new RuntimeException(e);
69          }
70      }
71  
72      /**
73       * @see org.kuali.kfs.module.bc.document.validation.BudgetExpansionRule#processExpansionRule(org.kuali.kfs.module.bc.document.validation.event.BudgetExpansionEvent)
74       */
75      public boolean processExpansionRule(BudgetExpansionEvent budgetExpansionEvent) {
76          boolean valid = true;
77  
78          Class<? extends BusinessRule> expansionRuleClass = budgetExpansionEvent.getExpansionRuleInterfaceClass();
79          for (BusinessRule expansionRule : expansionRules) {
80              if (expansionRuleClass.isAssignableFrom(expansionRule.getClass())) {
81                  valid &= budgetExpansionEvent.invokeExpansionRuleMethod(expansionRule);
82              }
83          }
84  
85          return valid;
86      }
87  
88      /**
89       * @see org.kuali.rice.krad.rule.SaveDocumentRule#processSaveDocument(org.kuali.rice.krad.document.Document)
90       */
91      public boolean processSaveDocument(Document document) {
92          return ((SaveDocumentRule) budgetConstructionDocumentRules).processSaveDocument(document);
93      }
94  
95      /**
96       * @see org.kuali.kfs.module.bc.document.validation.AddBudgetConstructionDocumentRule#processAddBudgetConstructionDocumentRules(org.kuali.kfs.module.bc.document.BudgetConstructionDocument)
97       */
98      public boolean processAddBudgetConstructionDocumentRules(BudgetConstructionDocument budgetConstructionDocument) {
99          return ((AddBudgetConstructionDocumentRule<BudgetConstructionDocument>) budgetConstructionDocumentRules).processAddBudgetConstructionDocumentRules(budgetConstructionDocument);
100     }
101 
102     /**
103      * @see org.kuali.kfs.module.bc.document.validation.AddPendingBudgetGeneralLedgerLineRule#processAddPendingBudgetGeneralLedgerLineRules(org.kuali.kfs.module.bc.document.BudgetConstructionDocument,
104      *      org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionGeneralLedger, boolean)
105      */
106     public boolean processAddPendingBudgetGeneralLedgerLineRules(BudgetConstructionDocument budgetConstructionDocument, PendingBudgetConstructionGeneralLedger pendingBudgetConstructionGeneralLedger, boolean isRevenue) {
107         return ((AddPendingBudgetGeneralLedgerLineRule<BudgetConstructionDocument, PendingBudgetConstructionGeneralLedger>) budgetConstructionDocumentRules).processAddPendingBudgetGeneralLedgerLineRules(budgetConstructionDocument, pendingBudgetConstructionGeneralLedger, isRevenue);
108     }
109 
110     /**
111      * @see org.kuali.kfs.module.bc.document.validation.DeletePendingBudgetGeneralLedgerLineRule#processDeletePendingBudgetGeneralLedgerLineRules(org.kuali.kfs.module.bc.document.BudgetConstructionDocument,
112      *      org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionGeneralLedger, boolean)
113      */
114     public boolean processDeletePendingBudgetGeneralLedgerLineRules(BudgetConstructionDocument budgetConstructionDocument, PendingBudgetConstructionGeneralLedger pendingBudgetConstructionGeneralLedger, boolean isRevenue) {
115         return ((DeletePendingBudgetGeneralLedgerLineRule<BudgetConstructionDocument, PendingBudgetConstructionGeneralLedger>) budgetConstructionDocumentRules).processDeletePendingBudgetGeneralLedgerLineRules(budgetConstructionDocument, pendingBudgetConstructionGeneralLedger, isRevenue);
116     }
117 
118     /**
119      * @see org.kuali.kfs.module.bc.document.validation.DeleteMonthlySpreadRule#processDeleteMonthlySpreadRules(org.kuali.kfs.module.bc.document.BudgetConstructionDocument,
120      *      org.kuali.kfs.module.bc.BCConstants.MonthSpreadDeleteType)
121      */
122     public boolean processDeleteMonthlySpreadRules(BudgetConstructionDocument budgetConstructionDocument, MonthSpreadDeleteType monthSpreadDeleteType) {
123         return ((DeleteMonthlySpreadRule<BudgetConstructionDocument>) budgetConstructionDocumentRules).processDeleteMonthlySpreadRules(budgetConstructionDocument, monthSpreadDeleteType);
124     }
125 
126     public boolean processSaveMonthlyBudgetRules(BudgetConstructionDocument budgetConstructionDocument, BudgetConstructionMonthly budgetConstructionMonthly){
127         return ((SaveMonthlyBudgetRule<BudgetConstructionDocument, BudgetConstructionMonthly>) budgetConstructionDocumentRules).processSaveMonthlyBudgetRules(budgetConstructionDocument, budgetConstructionMonthly);
128     }
129     /**
130      * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processAddAppointmentFunding(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
131      */
132     public boolean processAddAppointmentFunding(List<PendingBudgetConstructionAppointmentFunding> existingAppointmentFundings, PendingBudgetConstructionAppointmentFunding appointmentFunding, SynchronizationCheckType synchronizationCheckType) {
133         return salarySettingRules.processAddAppointmentFunding(existingAppointmentFundings, appointmentFunding, synchronizationCheckType);
134     }
135 
136     /**
137      * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processSaveAppointmentFunding(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
138      */
139     public boolean processSaveAppointmentFunding(PendingBudgetConstructionAppointmentFunding appointmentFunding, SynchronizationCheckType synchronizationCheckType) {
140         return salarySettingRules.processSaveAppointmentFunding(appointmentFunding, synchronizationCheckType);
141     }
142 
143     /**
144      * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processNormalizePayrateAndAmount(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
145      */
146     public boolean processNormalizePayrateAndAmount(PendingBudgetConstructionAppointmentFunding appointmentFunding) {
147         return salarySettingRules.processNormalizePayrateAndAmount(appointmentFunding);
148     }
149 
150     /**
151      * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processAdjustSalaraySettingLinePercent(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
152      */
153     public boolean processAdjustSalaraySettingLinePercent(PendingBudgetConstructionAppointmentFunding appointmentFunding) {
154         return salarySettingRules.processAdjustSalaraySettingLinePercent(appointmentFunding);
155     }
156 
157     /**
158      * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processQuickSaveAppointmentFunding(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
159      */
160     public boolean processQuickSaveAppointmentFunding(PendingBudgetConstructionAppointmentFunding appointmentFunding) {
161         return salarySettingRules.processQuickSaveAppointmentFunding(appointmentFunding);
162     }
163 }