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.kra.budget.web.struts.action;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import javax.servlet.http.HttpServletResponse;
023:
024: import org.apache.struts.action.ActionForm;
025: import org.apache.struts.action.ActionForward;
026: import org.apache.struts.action.ActionMapping;
027: import org.kuali.core.service.KualiRuleService;
028: import org.kuali.kfs.KFSConstants;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.module.kra.budget.bo.BudgetIndirectCost;
031: import org.kuali.module.kra.budget.bo.BudgetIndirectCostLookup;
032: import org.kuali.module.kra.budget.rules.event.RecalculateIndirectCostEvent;
033: import org.kuali.module.kra.budget.rules.event.UpdateIndirectCostEvent;
034: import org.kuali.module.kra.budget.service.BudgetIndirectCostService;
035: import org.kuali.module.kra.budget.web.struts.form.BudgetForm;
036: import org.kuali.module.kra.budget.web.struts.form.BudgetIndirectCostFormHelper;
037:
038: /**
039: * This class handles Actions for Research Administration.
040: */
041:
042: public class BudgetIndirectCostAction extends BudgetAction {
043:
044: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045: .getLogger(BudgetIndirectCostAction.class);
046:
047: /**
048: * Save indirect Cost.
049: *
050: * @param mapping
051: * @param form
052: * @param request
053: * @param response
054: * @return ActionForward
055: * @throws Exception
056: */
057: public ActionForward save(ActionMapping mapping, ActionForm form,
058: HttpServletRequest request, HttpServletResponse response)
059: throws Exception {
060:
061: BudgetForm budgetForm = (BudgetForm) form;
062:
063: SpringContext.getBean(BudgetIndirectCostService.class)
064: .refreshIndirectCost(budgetForm.getBudgetDocument());
065: budgetForm
066: .setBudgetIndirectCostFormHelper(new BudgetIndirectCostFormHelper(
067: budgetForm));
068:
069: // Check to make sure our rules are passed.
070: boolean rulePassed = SpringContext.getBean(
071: KualiRuleService.class).applyRules(
072: new UpdateIndirectCostEvent(budgetForm.getDocument(),
073: budgetForm.getBudgetDocument().getBudget()
074: .getIndirectCost()));
075:
076: // If our rule failed, reload the current page.
077: if (!rulePassed) {
078: return mapping.findForward(KFSConstants.MAPPING_BASIC);
079: }
080:
081: BudgetIndirectCost indirectCost = new BudgetIndirectCost(
082: budgetForm.getBudgetDocument().getBudget()
083: .getIndirectCost());
084: indirectCost.setDocumentNumber(budgetForm.getBudgetDocument()
085: .getDocumentNumber());
086:
087: List<BudgetIndirectCostLookup> budgetIndirectCostLookups = new ArrayList(
088: budgetForm.getBudgetDocument().getBudget()
089: .getBudgetIndirectCostLookups());
090:
091: // we are only saving indirect cost items, so load the doc and
092: // set the indirect cost items to the proper ones.
093: this .load(mapping, form, request, response);
094: budgetForm.getBudgetDocument().getBudget().setIndirectCost(
095: indirectCost);
096: budgetForm
097: .getBudgetDocument()
098: .getBudget()
099: .setBudgetIndirectCostLookups(budgetIndirectCostLookups);
100:
101: super .save(mapping, form, request, response);
102:
103: return mapping.findForward(KFSConstants.MAPPING_BASIC);
104: }
105:
106: /**
107: * Recalculate values based on updated IDC parameters. If there are errors in the new parameters, do not do the recalculations.
108: *
109: * @param mapping
110: * @param form
111: * @param request
112: * @param response
113: * @return ActionForward
114: * @throws Exception
115: */
116: public ActionForward recalculate(ActionMapping mapping,
117: ActionForm form, HttpServletRequest request,
118: HttpServletResponse response) throws Exception {
119:
120: BudgetForm budgetForm = (BudgetForm) form;
121:
122: // Check to make sure our rules are passed.
123: boolean rulePassed = SpringContext.getBean(
124: KualiRuleService.class).applyRules(
125: new RecalculateIndirectCostEvent(budgetForm
126: .getDocument()));
127:
128: // If our rule passed, update all our values. Otherwise, reload the page.
129: if (rulePassed) {
130:
131: // Make sure our IDC object is properly formed. This will also perform initial calculations for
132: // BudgetTaskPeriodIndirectCost objects.
133: SpringContext
134: .getBean(BudgetIndirectCostService.class)
135: .refreshIndirectCost(budgetForm.getBudgetDocument());
136:
137: // This will populate task and period totals in HashMaps so they can be pulled in the view.
138: budgetForm
139: .setBudgetIndirectCostFormHelper(new BudgetIndirectCostFormHelper(
140: budgetForm));
141: }
142:
143: return this .update(mapping, form, request, response);
144: }
145:
146: public ActionForward reload(ActionMapping mapping, ActionForm form,
147: HttpServletRequest request, HttpServletResponse response)
148: throws Exception {
149: ActionForward forward = super .reload(mapping, form, request,
150: response);
151:
152: BudgetForm budgetForm = (BudgetForm) form;
153: SpringContext.getBean(BudgetIndirectCostService.class)
154: .refreshIndirectCost(budgetForm.getBudgetDocument());
155: budgetForm
156: .setBudgetIndirectCostFormHelper(new BudgetIndirectCostFormHelper(
157: budgetForm));
158:
159: return forward;
160: }
161: }
|