001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.module.bc.document.validation.impl;
017    
018    import java.util.ArrayList;
019    import java.util.Collection;
020    import java.util.List;
021    
022    import org.kuali.kfs.module.bc.BCConstants.MonthSpreadDeleteType;
023    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionMonthly;
024    import org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding;
025    import org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionGeneralLedger;
026    import org.kuali.kfs.module.bc.document.BudgetConstructionDocument;
027    import org.kuali.kfs.module.bc.document.validation.AddBudgetConstructionDocumentRule;
028    import org.kuali.kfs.module.bc.document.validation.AddPendingBudgetGeneralLedgerLineRule;
029    import org.kuali.kfs.module.bc.document.validation.BudgetExpansionRule;
030    import org.kuali.kfs.module.bc.document.validation.DeleteMonthlySpreadRule;
031    import org.kuali.kfs.module.bc.document.validation.DeletePendingBudgetGeneralLedgerLineRule;
032    import org.kuali.kfs.module.bc.document.validation.SalarySettingRule;
033    import org.kuali.kfs.module.bc.document.validation.SaveMonthlyBudgetRule;
034    import org.kuali.kfs.module.bc.document.validation.event.BudgetExpansionEvent;
035    import org.kuali.rice.kns.document.Document;
036    import org.kuali.rice.kns.rule.BusinessRule;
037    import org.kuali.rice.kns.rule.SaveDocumentRule;
038    
039    /**
040     * Base rule class for Budget Construction. Handles calling other expansion rule classes and the core budget document rules.
041     */
042    public class BudgetConstructionRules implements BudgetExpansionRule, SalarySettingRule, SaveDocumentRule, AddBudgetConstructionDocumentRule<BudgetConstructionDocument>, AddPendingBudgetGeneralLedgerLineRule<BudgetConstructionDocument, PendingBudgetConstructionGeneralLedger>, DeletePendingBudgetGeneralLedgerLineRule<BudgetConstructionDocument, PendingBudgetConstructionGeneralLedger>, DeleteMonthlySpreadRule<BudgetConstructionDocument>, SaveMonthlyBudgetRule<BudgetConstructionDocument, BudgetConstructionMonthly> {
043        private Collection<BusinessRule> expansionRules;
044        private BudgetConstructionDocumentRules budgetConstructionDocumentRules;
045        private SalarySettingRule salarySettingRules;
046    
047        /**
048         * Initialize expansion rule classes.
049         */
050        public BudgetConstructionRules() {
051            expansionRules = new ArrayList<BusinessRule>();
052    
053            try {
054                budgetConstructionDocumentRules = BudgetConstructionDocumentRules.class.newInstance();
055                expansionRules.add(budgetConstructionDocumentRules);
056    
057                salarySettingRules = SalarySettingRules.class.newInstance();
058                expansionRules.add(salarySettingRules);
059            }
060            catch (InstantiationException e) {
061                throw new RuntimeException(e);
062            }
063            catch (IllegalAccessException e) {
064                throw new RuntimeException(e);
065            }
066        }
067    
068        /**
069         * @see org.kuali.kfs.module.bc.document.validation.BudgetExpansionRule#processExpansionRule(org.kuali.kfs.module.bc.document.validation.event.BudgetExpansionEvent)
070         */
071        public boolean processExpansionRule(BudgetExpansionEvent budgetExpansionEvent) {
072            boolean valid = true;
073    
074            Class<? extends BusinessRule> expansionRuleClass = budgetExpansionEvent.getExpansionRuleInterfaceClass();
075            for (BusinessRule expansionRule : expansionRules) {
076                if (expansionRuleClass.isAssignableFrom(expansionRule.getClass())) {
077                    valid &= budgetExpansionEvent.invokeExpansionRuleMethod(expansionRule);
078                }
079            }
080    
081            return valid;
082        }
083    
084        /**
085         * @see org.kuali.rice.kns.rule.SaveDocumentRule#processSaveDocument(org.kuali.rice.kns.document.Document)
086         */
087        public boolean processSaveDocument(Document document) {
088            return ((SaveDocumentRule) budgetConstructionDocumentRules).processSaveDocument(document);
089        }
090    
091        /**
092         * @see org.kuali.kfs.module.bc.document.validation.AddBudgetConstructionDocumentRule#processAddBudgetConstructionDocumentRules(org.kuali.kfs.module.bc.document.BudgetConstructionDocument)
093         */
094        public boolean processAddBudgetConstructionDocumentRules(BudgetConstructionDocument budgetConstructionDocument) {
095            return ((AddBudgetConstructionDocumentRule<BudgetConstructionDocument>) budgetConstructionDocumentRules).processAddBudgetConstructionDocumentRules(budgetConstructionDocument);
096        }
097    
098        /**
099         * @see org.kuali.kfs.module.bc.document.validation.AddPendingBudgetGeneralLedgerLineRule#processAddPendingBudgetGeneralLedgerLineRules(org.kuali.kfs.module.bc.document.BudgetConstructionDocument,
100         *      org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionGeneralLedger, boolean)
101         */
102        public boolean processAddPendingBudgetGeneralLedgerLineRules(BudgetConstructionDocument budgetConstructionDocument, PendingBudgetConstructionGeneralLedger pendingBudgetConstructionGeneralLedger, boolean isRevenue) {
103            return ((AddPendingBudgetGeneralLedgerLineRule<BudgetConstructionDocument, PendingBudgetConstructionGeneralLedger>) budgetConstructionDocumentRules).processAddPendingBudgetGeneralLedgerLineRules(budgetConstructionDocument, pendingBudgetConstructionGeneralLedger, isRevenue);
104        }
105    
106        /**
107         * @see org.kuali.kfs.module.bc.document.validation.DeletePendingBudgetGeneralLedgerLineRule#processDeletePendingBudgetGeneralLedgerLineRules(org.kuali.kfs.module.bc.document.BudgetConstructionDocument,
108         *      org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionGeneralLedger, boolean)
109         */
110        public boolean processDeletePendingBudgetGeneralLedgerLineRules(BudgetConstructionDocument budgetConstructionDocument, PendingBudgetConstructionGeneralLedger pendingBudgetConstructionGeneralLedger, boolean isRevenue) {
111            return ((DeletePendingBudgetGeneralLedgerLineRule<BudgetConstructionDocument, PendingBudgetConstructionGeneralLedger>) budgetConstructionDocumentRules).processDeletePendingBudgetGeneralLedgerLineRules(budgetConstructionDocument, pendingBudgetConstructionGeneralLedger, isRevenue);
112        }
113    
114        /**
115         * @see org.kuali.kfs.module.bc.document.validation.DeleteMonthlySpreadRule#processDeleteMonthlySpreadRules(org.kuali.kfs.module.bc.document.BudgetConstructionDocument,
116         *      org.kuali.kfs.module.bc.BCConstants.MonthSpreadDeleteType)
117         */
118        public boolean processDeleteMonthlySpreadRules(BudgetConstructionDocument budgetConstructionDocument, MonthSpreadDeleteType monthSpreadDeleteType) {
119            return ((DeleteMonthlySpreadRule<BudgetConstructionDocument>) budgetConstructionDocumentRules).processDeleteMonthlySpreadRules(budgetConstructionDocument, monthSpreadDeleteType);
120        }
121    
122        public boolean processSaveMonthlyBudgetRules(BudgetConstructionDocument budgetConstructionDocument, BudgetConstructionMonthly budgetConstructionMonthly){
123            return ((SaveMonthlyBudgetRule<BudgetConstructionDocument, BudgetConstructionMonthly>) budgetConstructionDocumentRules).processSaveMonthlyBudgetRules(budgetConstructionDocument, budgetConstructionMonthly);
124        }
125        /**
126         * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processAddAppointmentFunding(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
127         */
128        public boolean processAddAppointmentFunding(List<PendingBudgetConstructionAppointmentFunding> existingAppointmentFundings, PendingBudgetConstructionAppointmentFunding appointmentFunding) {
129            return salarySettingRules.processAddAppointmentFunding(existingAppointmentFundings, appointmentFunding);
130        }
131    
132        /**
133         * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processSaveAppointmentFunding(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
134         */
135        public boolean processSaveAppointmentFunding(PendingBudgetConstructionAppointmentFunding appointmentFunding) {
136            return salarySettingRules.processSaveAppointmentFunding(appointmentFunding);
137        }
138    
139        /**
140         * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processNormalizePayrateAndAmount(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
141         */
142        public boolean processNormalizePayrateAndAmount(PendingBudgetConstructionAppointmentFunding appointmentFunding) {
143            return salarySettingRules.processNormalizePayrateAndAmount(appointmentFunding);
144        }
145    
146        /**
147         * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processAdjustSalaraySettingLinePercent(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
148         */
149        public boolean processAdjustSalaraySettingLinePercent(PendingBudgetConstructionAppointmentFunding appointmentFunding) {
150            return salarySettingRules.processAdjustSalaraySettingLinePercent(appointmentFunding);
151        }
152    
153        /**
154         * @see org.kuali.kfs.module.bc.document.validation.SalarySettingRule#processQuickSaveAppointmentFunding(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding)
155         */
156        public boolean processQuickSaveAppointmentFunding(PendingBudgetConstructionAppointmentFunding appointmentFunding) {
157            return salarySettingRules.processQuickSaveAppointmentFunding(appointmentFunding);
158        }
159    }