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.kfs.KFSConstants;
028: import org.kuali.module.kra.budget.bo.Budget;
029: import org.kuali.module.kra.budget.bo.BudgetInstitutionCostShare;
030: import org.kuali.module.kra.budget.bo.BudgetPeriod;
031: import org.kuali.module.kra.budget.bo.BudgetThirdPartyCostShare;
032: import org.kuali.module.kra.budget.web.struts.form.BudgetCostShareFormHelper;
033: import org.kuali.module.kra.budget.web.struts.form.BudgetForm;
034:
035: /**
036: * Action for BudgetCostShare page.
037: */
038: public class BudgetCostShareAction extends BudgetAction {
039:
040: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
041: .getLogger(BudgetParametersAction.class);
042:
043: /**
044: * Data preparation for Cost Share page.
045: *
046: * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm,
047: * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
048: */
049: public ActionForward execute(ActionMapping mapping,
050: ActionForm form, HttpServletRequest request,
051: HttpServletResponse response) throws Exception {
052: BudgetForm budgetForm = (BudgetForm) form;
053: Budget budget = budgetForm.getBudgetDocument().getBudget();
054:
055: // Partial re-load to avoid lots of hidden variables.
056: budget.refreshReferenceObject("personnel");
057: budget.refreshReferenceObject("nonpersonnelItems");
058: budget.refreshReferenceObject("indirectCost");
059:
060: // super.execute has to be called before re-creating BudgetCostShareFormHelper because the super call may
061: // completly reload data such as for example for the reload button
062: ActionForward forward = super .execute(mapping, form, request,
063: response);
064:
065: budgetForm
066: .setBudgetCostShareFormHelper(new BudgetCostShareFormHelper(
067: budgetForm));
068:
069: setupBudgetCostSharePermissionDisplay(budgetForm);
070:
071: return forward;
072: }
073:
074: /**
075: * Recalculate button.
076: *
077: * @param mapping
078: * @param form
079: * @param request
080: * @param response
081: * @return
082: * @throws Exception
083: */
084: public ActionForward recalculate(ActionMapping mapping,
085: ActionForm form, HttpServletRequest request,
086: HttpServletResponse response) throws Exception {
087:
088: // execute method already does this work.
089:
090: return super .update(mapping, form, request, response);
091: }
092:
093: /**
094: * Insert Institution Cost Share button.
095: *
096: * @param mapping
097: * @param form
098: * @param request
099: * @param response
100: * @return
101: * @throws Exception
102: */
103: public ActionForward insertInstitutionCostShareDirect(
104: ActionMapping mapping, ActionForm form,
105: HttpServletRequest request, HttpServletResponse response)
106: throws Exception {
107: BudgetForm budgetForm = (BudgetForm) form;
108:
109: // Add the new institution cost share item and create a new one
110: budgetForm.getBudgetDocument()
111: .addInstitutionCostShare(
112: budgetForm.getBudgetDocument().getBudget()
113: .getPeriods(),
114: budgetForm.getNewInstitutionCostShare());
115: budgetForm
116: .setNewInstitutionCostShare(new BudgetInstitutionCostShare());
117:
118: // Make sure new values are taken into account for calculations.
119: budgetForm
120: .setBudgetCostShareFormHelper(new BudgetCostShareFormHelper(
121: budgetForm));
122: budgetForm.getNewInstitutionCostShare().setPermissionIndicator(
123: true);
124:
125: return mapping.findForward(KFSConstants.MAPPING_BASIC);
126: }
127:
128: /**
129: * Delete Institution Cost Share button.
130: *
131: * @param mapping
132: * @param form
133: * @param request
134: * @param response
135: * @return
136: * @throws Exception
137: */
138: public ActionForward deleteInstitutionCostShareDirect(
139: ActionMapping mapping, ActionForm form,
140: HttpServletRequest request, HttpServletResponse response)
141: throws Exception {
142: BudgetForm budgetForm = (BudgetForm) form;
143:
144: budgetForm.getBudgetDocument().getBudget()
145: .getInstitutionCostShareItems().remove(
146: getLineToDelete(request));
147:
148: // Make sure new values are taken into account for calculations.
149: budgetForm
150: .setBudgetCostShareFormHelper(new BudgetCostShareFormHelper(
151: budgetForm));
152:
153: return mapping.findForward(KFSConstants.MAPPING_BASIC);
154: }
155:
156: /**
157: * Insert Third Party Cost Share button.
158: *
159: * @param mapping
160: * @param form
161: * @param request
162: * @param response
163: * @return
164: * @throws Exception
165: */
166: public ActionForward insertThirdPartyCostShareDirect(
167: ActionMapping mapping, ActionForm form,
168: HttpServletRequest request, HttpServletResponse response)
169: throws Exception {
170: BudgetForm budgetForm = (BudgetForm) form;
171:
172: // Add the new third party cost share item and create a new one
173: budgetForm.getBudgetDocument()
174: .addThirdPartyCostShare(
175: budgetForm.getBudgetDocument().getBudget()
176: .getPeriods(),
177: budgetForm.getNewThirdPartyCostShare());
178: budgetForm
179: .setNewThirdPartyCostShare(new BudgetThirdPartyCostShare());
180:
181: // Make sure new values are taken into account for calculations.
182: budgetForm
183: .setBudgetCostShareFormHelper(new BudgetCostShareFormHelper(
184: budgetForm));
185:
186: return mapping.findForward(KFSConstants.MAPPING_BASIC);
187: }
188:
189: /**
190: * Delete Third Party Cost Share button.
191: *
192: * @param mapping
193: * @param form
194: * @param request
195: * @param response
196: * @return
197: * @throws Exception
198: */
199: public ActionForward deleteThirdPartyCostShare(
200: ActionMapping mapping, ActionForm form,
201: HttpServletRequest request, HttpServletResponse response)
202: throws Exception {
203: BudgetForm budgetForm = (BudgetForm) form;
204:
205: budgetForm.getBudgetDocument().getBudget()
206: .getThirdPartyCostShareItems().remove(
207: getLineToDelete(request));
208:
209: // Make sure new values are taken into account for calculations.
210: budgetForm
211: .setBudgetCostShareFormHelper(new BudgetCostShareFormHelper(
212: budgetForm));
213:
214: return mapping.findForward(KFSConstants.MAPPING_BASIC);
215: }
216:
217: /**
218: * Save button.
219: *
220: * @param mapping
221: * @param form
222: * @param request
223: * @param response
224: * @return
225: * @throws Exception
226: */
227: public ActionForward saveBudgetCostShare(ActionMapping mapping,
228: ActionForm form, HttpServletRequest request,
229: HttpServletResponse response) throws Exception {
230: BudgetForm budgetForm = (BudgetForm) form;
231: Budget budget = budgetForm.getBudgetDocument().getBudget();
232: List<BudgetPeriod> periods = budgetForm.getBudgetDocument()
233: .getBudget().getPeriods();
234:
235: Integer institutionCostShareNextSequenceNumber = budgetForm
236: .getBudgetDocument()
237: .getInstitutionCostShareNextSequenceNumber();
238: Integer thirdPartyCostShareNextSequenceNumber = budgetForm
239: .getBudgetDocument()
240: .getThirdPartyCostShareNextSequenceNumber();
241: List institutionCostShare = new ArrayList(budget
242: .getInstitutionCostShareItems());
243: List institutionCostSharePersonnel = new ArrayList(budget
244: .getInstitutionCostSharePersonnelItems());
245: List thirdPartyCostShare = new ArrayList(budget
246: .getThirdPartyCostShareItems());
247:
248: this .load(mapping, form, request, response);
249:
250: // Only set the objects that potentially changed. The interface doesn't keep hiddens for fields that arn't used. Careful
251: // not to use "budget" variable above, that doesn't effect budgetForm.
252: if (budget.isInstitutionCostShareIndicator()) {
253: budgetForm.getBudgetDocument()
254: .setInstitutionCostShareNextSequenceNumber(
255: institutionCostShareNextSequenceNumber);
256: budgetForm.getBudgetDocument().getBudget()
257: .setInstitutionCostShareItems(institutionCostShare);
258: budgetForm.getBudgetDocument().getBudget()
259: .setInstitutionCostSharePersonnelItems(
260: institutionCostSharePersonnel);
261: }
262: if (budget.isBudgetThirdPartyCostShareIndicator()) {
263: budgetForm.getBudgetDocument()
264: .setThirdPartyCostShareNextSequenceNumber(
265: thirdPartyCostShareNextSequenceNumber);
266: budgetForm.getBudgetDocument().getBudget()
267: .setThirdPartyCostShareItems(thirdPartyCostShare);
268: }
269:
270: return super .save(mapping, form, request, response);
271: }
272:
273: @Override
274: public ActionForward reload(ActionMapping mapping, ActionForm form,
275: HttpServletRequest request, HttpServletResponse response)
276: throws Exception {
277: ActionForward forward = super .reload(mapping, form, request,
278: response);
279: ((BudgetForm) form).getNewInstitutionCostShare()
280: .setPermissionIndicator(true);
281: return forward;
282: }
283: }
|