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.KualiConfigurationService;
028: import org.kuali.core.service.KualiRuleService;
029: import org.kuali.core.service.PersistenceService;
030: import org.kuali.core.util.GlobalVariables;
031: import org.kuali.core.util.ObjectUtils;
032: import org.kuali.kfs.KFSConstants;
033: import org.kuali.kfs.context.SpringContext;
034: import org.kuali.kfs.service.ParameterService;
035: import org.kuali.module.kra.KraConstants;
036: import org.kuali.module.kra.budget.bo.AgencyExtension;
037: import org.kuali.module.kra.budget.bo.Budget;
038: import org.kuali.module.kra.budget.bo.BudgetFringeRate;
039: import org.kuali.module.kra.budget.bo.BudgetGraduateAssistantRate;
040: import org.kuali.module.kra.budget.bo.BudgetModular;
041: import org.kuali.module.kra.budget.bo.BudgetPeriod;
042: import org.kuali.module.kra.budget.bo.BudgetTask;
043: import org.kuali.module.kra.budget.bo.GraduateAssistantRate;
044: import org.kuali.module.kra.budget.document.BudgetDocument;
045: import org.kuali.module.kra.budget.rules.event.InsertPeriodLineEventBase;
046: import org.kuali.module.kra.budget.service.BudgetFringeRateService;
047: import org.kuali.module.kra.budget.service.BudgetModularService;
048: import org.kuali.module.kra.budget.web.struts.form.BudgetForm;
049:
050: /**
051: * This class handles Actions for Research Administration.
052: */
053:
054: public class BudgetParametersAction extends BudgetAction {
055:
056: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
057: .getLogger(BudgetParametersAction.class);
058:
059: /**
060: * This method overrides the BudgetAction execute method. It does so for the purpose of recalculating Personnel expenses any
061: * time the Personnel page is accessed
062: */
063: public ActionForward execute(ActionMapping mapping,
064: ActionForm form, HttpServletRequest request,
065: HttpServletResponse response) throws Exception {
066: ActionForward super Forward = super .execute(mapping, form,
067: request, response);
068:
069: BudgetForm budgetForm = (BudgetForm) form;
070:
071: // On first load, set the default task name for the initial task.
072: if (budgetForm.getBudgetDocument().getTaskListSize() == 0) {
073: String DEFAULT_BUDGET_TASK_NAME = SpringContext.getBean(
074: ParameterService.class).getParameterValue(
075: BudgetDocument.class,
076: KraConstants.DEFAULT_BUDGET_TASK_NAME);
077: budgetForm.getNewTask().setBudgetTaskName(
078: DEFAULT_BUDGET_TASK_NAME + " 1");
079: budgetForm.getNewTask().setBudgetTaskOnCampus(true);
080: }
081:
082: // Set default budget types
083: setupBudgetTypes(budgetForm);
084:
085: // pre-fetch academic year subdivision names for later use
086: setupAcademicYearSubdivisionConstants(budgetForm);
087:
088: // Disable/enable appropriate navigation tabs
089: budgetForm.checkHeaderNavigation();
090:
091: return super Forward;
092: }
093:
094: public ActionForward saveParameters(ActionMapping mapping,
095: ActionForm form, HttpServletRequest request,
096: HttpServletResponse response) throws Exception {
097: BudgetForm budgetForm = (BudgetForm) form;
098:
099: // Need to retain modular task number, since it's set on this page
100: Integer budgetModularTaskNumber = null;
101: if (!ObjectUtils.isNull(budgetForm.getBudgetDocument()
102: .getBudget().getModularBudget())) {
103: budgetModularTaskNumber = budgetForm.getBudgetDocument()
104: .getBudget().getModularBudget()
105: .getBudgetModularTaskNumber();
106: }
107:
108: List referenceObjects = new ArrayList();
109:
110: referenceObjects.add("budgetAgency");
111: referenceObjects.add("federalPassThroughAgency");
112: referenceObjects.add("projectDirector");
113: referenceObjects.add("nonpersonnelItems");
114: referenceObjects.add("personnel");
115: referenceObjects.add("modularBudget");
116: referenceObjects.add("indirectCost");
117: referenceObjects.add("thirdPartyCostShareItems");
118: referenceObjects.add("institutionCostShareItems");
119: referenceObjects.add("institutionCostSharePersonnelItems");
120:
121: SpringContext.getBean(PersistenceService.class)
122: .retrieveReferenceObjects(
123: budgetForm.getBudgetDocument().getBudget(),
124: referenceObjects);
125:
126: List docReferenceObjects = new ArrayList();
127: docReferenceObjects.add("adhocPersons");
128: docReferenceObjects.add("adhocOrgs");
129: docReferenceObjects.add("adhocWorkgroups");
130:
131: SpringContext.getBean(PersistenceService.class)
132: .retrieveReferenceObjects(
133: budgetForm.getBudgetDocument(),
134: docReferenceObjects);
135:
136: if (budgetForm.getBudgetDocument().getBudget()
137: .isAgencyModularIndicator()) {
138: if (ObjectUtils.isNull(budgetForm.getBudgetDocument()
139: .getBudget().getModularBudget())) {
140: // Modular budget with no modular data generated. So generate it.
141: SpringContext.getBean(BudgetModularService.class)
142: .generateModularBudget(
143: budgetForm.getBudgetDocument()
144: .getBudget());
145: }
146: budgetForm.getBudgetDocument().getBudget()
147: .getModularBudget().setBudgetModularTaskNumber(
148: budgetModularTaskNumber);
149: }
150:
151: Object question = request
152: .getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
153: KualiConfigurationService kualiConfiguration = SpringContext
154: .getBean(KualiConfigurationService.class);
155:
156: // Logic for Cost Share question.
157: ActionForward preRulesForward = preRulesCheck(mapping, form,
158: request, response, "saveParameters");
159: if (preRulesForward != null) {
160: return preRulesForward;
161: }
162:
163: super .save(mapping, form, request, response);
164:
165: if (GlobalVariables.getErrorMap().size() == 0) {
166: if (budgetForm.isAuditActivated()) {
167: return mapping.findForward("auditmode");
168: }
169:
170: // This is so that tab states are not shared between parameters and overview.
171: budgetForm.newTabState(true, true);
172:
173: return super .overview(mapping, budgetForm, request,
174: response);
175: }
176:
177: return mapping.findForward(KFSConstants.MAPPING_BASIC);
178: }
179:
180: public ActionForward copyFringeRateLines(ActionMapping mapping,
181: ActionForm form, HttpServletRequest request,
182: HttpServletResponse response) throws Exception {
183: // get the form
184: BudgetForm budgetForm = (BudgetForm) form;
185:
186: BudgetFringeRateService bfrService = SpringContext
187: .getBean(BudgetFringeRateService.class);
188: for (BudgetFringeRate budgetFringeRate : budgetForm
189: .getBudgetDocument().getBudget().getFringeRates()) {
190: budgetFringeRate
191: .setContractsAndGrantsFringeRateAmount(budgetFringeRate
192: .getAppointmentTypeFringeRateAmount());
193: }
194:
195: return mapping.findForward(KFSConstants.MAPPING_BASIC);
196: }
197:
198: public ActionForward copyInstitutionCostShareLines(
199: ActionMapping mapping, ActionForm form,
200: HttpServletRequest request, HttpServletResponse response)
201: throws Exception {
202: // get the form
203: BudgetForm budgetForm = (BudgetForm) form;
204:
205: BudgetFringeRateService bfrService = SpringContext
206: .getBean(BudgetFringeRateService.class);
207: for (BudgetFringeRate budgetFringeRate : budgetForm
208: .getBudgetDocument().getBudget().getFringeRates()) {
209: budgetFringeRate
210: .setInstitutionCostShareFringeRateAmount(budgetFringeRate
211: .getAppointmentTypeCostShareFringeRateAmount());
212: }
213:
214: return mapping.findForward(KFSConstants.MAPPING_BASIC);
215: }
216:
217: /*
218: * A struts action to copy the the Graduate Asst. rates from the system rate to the current budget
219: */
220: public ActionForward copySystemGraduateAssistantLines(
221: ActionMapping mapping, ActionForm form,
222: HttpServletRequest request, HttpServletResponse response)
223: throws Exception {
224: // get the form
225: BudgetForm budgetForm = (BudgetForm) form;
226:
227: for (BudgetGraduateAssistantRate budgetGraduateAssistantRate : budgetForm
228: .getBudgetDocument().getBudget()
229: .getGraduateAssistantRates()) {
230: budgetGraduateAssistantRate
231: .refreshNonUpdateableReferences();
232: GraduateAssistantRate systemRate = budgetGraduateAssistantRate
233: .getGraduateAssistantRate();
234: budgetGraduateAssistantRate
235: .setCampusMaximumPeriod1Rate(systemRate
236: .getCampusMaximumPeriod1Rate());
237: budgetGraduateAssistantRate
238: .setCampusMaximumPeriod2Rate(systemRate
239: .getCampusMaximumPeriod2Rate());
240: budgetGraduateAssistantRate
241: .setCampusMaximumPeriod3Rate(systemRate
242: .getCampusMaximumPeriod3Rate());
243: budgetGraduateAssistantRate
244: .setCampusMaximumPeriod4Rate(systemRate
245: .getCampusMaximumPeriod4Rate());
246: budgetGraduateAssistantRate
247: .setCampusMaximumPeriod5Rate(systemRate
248: .getCampusMaximumPeriod5Rate());
249: budgetGraduateAssistantRate
250: .setCampusMaximumPeriod6Rate(systemRate
251: .getCampusMaximumPeriod6Rate());
252: }
253:
254: return mapping.findForward(KFSConstants.MAPPING_BASIC);
255: }
256:
257: public ActionForward insertPeriodLine(ActionMapping mapping,
258: ActionForm form, HttpServletRequest request,
259: HttpServletResponse response) throws Exception {
260: BudgetForm budgetForm = (BudgetForm) form;
261:
262: // check any business rules
263: boolean rulePassed = SpringContext.getBean(
264: KualiRuleService.class).applyRules(
265: new InsertPeriodLineEventBase(budgetForm.getDocument(),
266: budgetForm.getNewPeriod()));
267:
268: if (rulePassed) {
269: budgetForm.getBudgetDocument().addPeriod(
270: budgetForm.getNewPeriod());
271: budgetForm.setNewPeriod(new BudgetPeriod());
272: }
273: return mapping.findForward(KFSConstants.MAPPING_BASIC);
274: }
275:
276: public ActionForward deletePeriodLine(ActionMapping mapping,
277: ActionForm form, HttpServletRequest request,
278: HttpServletResponse response) throws Exception {
279:
280: ((BudgetForm) form).getBudgetDocument().setPeriodToDelete(
281: Integer.toString(getLineToDelete(request)));
282: ActionForward preRulesForward = preRulesCheck(mapping, form,
283: request, response);
284: if (preRulesForward != null) {
285: return preRulesForward;
286: }
287:
288: return mapping.findForward(KFSConstants.MAPPING_BASIC);
289: }
290:
291: public ActionForward insertTaskLine(ActionMapping mapping,
292: ActionForm form, HttpServletRequest request,
293: HttpServletResponse response) throws Exception {
294: BudgetForm budgetForm = (BudgetForm) form;
295: budgetForm.getBudgetDocument().addTask(budgetForm.getNewTask());
296: budgetForm.setNewTask(new BudgetTask());
297: budgetForm.getNewTask().setBudgetTaskOnCampus(true);
298: return mapping.findForward(KFSConstants.MAPPING_BASIC);
299: }
300:
301: public ActionForward deleteTaskLine(ActionMapping mapping,
302: ActionForm form, HttpServletRequest request,
303: HttpServletResponse response) throws Exception {
304:
305: ((BudgetForm) form).getBudgetDocument().setTaskToDelete(
306: Integer.toString(getLineToDelete(request)));
307: ActionForward preRulesForward = preRulesCheck(mapping, form,
308: request, response);
309: if (preRulesForward != null) {
310: return preRulesForward;
311: }
312:
313: return mapping.findForward(KFSConstants.MAPPING_BASIC);
314: }
315:
316: public ActionForward refresh(ActionMapping mapping,
317: ActionForm form, HttpServletRequest request,
318: HttpServletResponse response) throws Exception {
319: super .refresh(mapping, form, request, response);
320: BudgetForm budgetForm = (BudgetForm) form;
321: Budget budget = budgetForm.getBudgetDocument().getBudget();
322: if (request.getParameter(KFSConstants.REFRESH_CALLER) != null) {
323: String refreshCaller = request
324: .getParameter(KFSConstants.REFRESH_CALLER);
325: // check to see if we are coming back from a lookup
326: if (refreshCaller
327: .equals(KFSConstants.KUALI_LOOKUPABLE_IMPL)) {
328: if ("true"
329: .equals(request
330: .getParameter("document.budget.agencyToBeNamedIndicator"))) {
331: // coming back from Agency lookup - To Be Named selected
332: budget.setBudgetAgency(null);
333: budget.setBudgetAgencyNumber(null);
334: BudgetModular modularBudget = budget
335: .getModularBudget() != null ? budget
336: .getModularBudget() : new BudgetModular(
337: budget.getDocumentNumber());
338: resetModularBudget(budget, modularBudget);
339: budget.setModularBudget(modularBudget);
340: } else if (request
341: .getParameter("document.budget.budgetAgencyNumber") != null) {
342: // coming back from an Agnecy lookup - Agency selected
343: budget.setAgencyToBeNamedIndicator(false);
344: BudgetModular modularBudget = budget
345: .getModularBudget() != null ? budget
346: .getModularBudget() : new BudgetModular(
347: budget.getDocumentNumber());
348: budget.refreshReferenceObject("budgetAgency");
349: budget.getBudgetAgency().refresh();
350: if (budget.getBudgetAgency().getAgencyExtension() != null) {
351: AgencyExtension agencyExtension = budget
352: .getBudgetAgency().getAgencyExtension();
353: modularBudget
354: .setBudgetModularIncrementAmount(agencyExtension
355: .getBudgetModularIncrementAmount());
356: modularBudget
357: .setBudgetPeriodMaximumAmount(agencyExtension
358: .getBudgetPeriodMaximumAmount());
359: } else {
360: resetModularBudget(budget, modularBudget);
361: }
362: budget.setModularBudget(modularBudget);
363: } else if (request
364: .getParameter("document.budget.budgetProjectDirectorUniversalIdentifier") != null) {
365: // Coming back from project director lookup - project director selected
366: budgetForm
367: .getBudgetDocument()
368: .getBudget()
369: .setProjectDirectorToBeNamedIndicator(false);
370: budgetForm.getBudgetDocument().getBudget()
371: .refreshReferenceObject("projectDirector");
372: } else if ("true"
373: .equals(request
374: .getParameter("document.budget.projectDirectorToBeNamedIndicator"))) {
375: // Coming back from project director lookup - Name Later selected
376: budgetForm.getBudgetDocument().getBudget()
377: .setProjectDirector(null);
378: budgetForm
379: .getBudgetDocument()
380: .getBudget()
381: .setBudgetProjectDirectorUniversalIdentifier(
382: null);
383: }
384: }
385: }
386: return mapping.findForward(KFSConstants.MAPPING_BASIC);
387: }
388:
389: private static void resetModularBudget(Budget budget,
390: BudgetModular modularBudget) {
391: modularBudget.setBudgetModularTaskNumber(null);
392: budget.setAgencyModularIndicator(false);
393: }
394:
395: public ActionForward clearFedPassthrough(ActionMapping mapping,
396: ActionForm form, HttpServletRequest request,
397: HttpServletResponse response) throws Exception {
398: BudgetForm budgetForm = (BudgetForm) form;
399: Budget budget = budgetForm.getBudgetDocument().getBudget();
400:
401: budget.setFederalPassThroughAgencyNumber(null);
402: budget.setFederalPassThroughAgency(null);
403:
404: return mapping.findForward(KFSConstants.MAPPING_BASIC);
405: }
406:
407: public ActionForward basic(ActionMapping mapping, ActionForm form,
408: HttpServletRequest request, HttpServletResponse response)
409: throws Exception {
410: return mapping.findForward(KFSConstants.MAPPING_BASIC);
411: }
412: }
|