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 javax.servlet.http.HttpServletRequest;
019: import javax.servlet.http.HttpServletResponse;
020:
021: import org.apache.struts.action.ActionForm;
022: import org.apache.struts.action.ActionForward;
023: import org.apache.struts.action.ActionMapping;
024: import org.kuali.core.authorization.AuthorizationConstants;
025: import org.kuali.core.service.DocumentAuthorizationService;
026: import org.kuali.core.service.KualiRuleService;
027: import org.kuali.kfs.KFSConstants;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.kra.budget.bo.BudgetModular;
030: import org.kuali.module.kra.budget.rules.event.EnterModularEvent;
031: import org.kuali.module.kra.budget.rules.event.SaveModularEvent;
032: import org.kuali.module.kra.budget.service.BudgetModularService;
033: import org.kuali.module.kra.budget.web.struts.form.BudgetForm;
034:
035: /**
036: * This class handles Actions for the Budget Modular page.
037: */
038: public class BudgetModularAction extends BudgetAction {
039:
040: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
041: .getLogger(BudgetModularAction.class);
042:
043: /**
044: * Save the form, and then reload/recalculate values.
045: *
046: * @param mapping
047: * @param form
048: * @param request
049: * @param response
050: * @throws Exception
051: */
052: public ActionForward saveAndRegenerate(ActionMapping mapping,
053: ActionForm form, HttpServletRequest request,
054: HttpServletResponse response) throws Exception {
055:
056: BudgetForm budgetForm = (BudgetForm) form;
057:
058: ActionForward forward = save(mapping, form, request, response);
059:
060: SpringContext.getBean(BudgetModularService.class)
061: .generateModularBudget(
062: budgetForm.getBudgetDocument().getBudget(),
063: budgetForm.getNonpersonnelCategories());
064:
065: SpringContext.getBean(KualiRuleService.class).applyRules(
066: new EnterModularEvent(budgetForm.getDocument()));
067:
068: return forward;
069: }
070:
071: /**
072: * Save the form.
073: *
074: * @param mapping
075: * @param form
076: * @param request
077: * @param response
078: * @throws Exception
079: */
080: public ActionForward save(ActionMapping mapping, ActionForm form,
081: HttpServletRequest request, HttpServletResponse response)
082: throws Exception {
083:
084: BudgetForm budgetForm = (BudgetForm) form;
085: BudgetModular modular = budgetForm.getBudgetDocument()
086: .getBudget().getModularBudget();
087:
088: this .load(mapping, budgetForm, request, response);
089: budgetForm.getBudgetDocument().getBudget().setModularBudget(
090: modular);
091:
092: // check business rules
093: boolean rulePassed = true;
094: budgetForm.populateAuthorizationFields(SpringContext.getBean(
095: DocumentAuthorizationService.class)
096: .getDocumentAuthorizer(budgetForm.getBudgetDocument()));
097: if (!"TRUE".equals(budgetForm.getEditingMode().get(
098: AuthorizationConstants.EditMode.VIEW_ONLY))) {
099: rulePassed = SpringContext.getBean(KualiRuleService.class)
100: .applyRules(
101: new SaveModularEvent(budgetForm
102: .getDocument()));
103: }
104:
105: ActionForward super Forward = mapping
106: .findForward(KFSConstants.MAPPING_BASIC);
107: if (rulePassed
108: && !budgetForm.getBudgetDocument().getBudget()
109: .getModularBudget().isInvalidMode()) {
110: super Forward = super .save(mapping, form, request, response);
111: }
112:
113: return super Forward;
114: }
115:
116: /**
117: * Recalculate the form values without saving/reloading.
118: *
119: * @param mapping
120: * @param form
121: * @param request
122: * @param response
123: * @throws Exception
124: */
125: public ActionForward recalculate(ActionMapping mapping,
126: ActionForm form, HttpServletRequest request,
127: HttpServletResponse response) throws Exception {
128: BudgetForm budgetForm = (BudgetForm) form;
129: BudgetModular modular = budgetForm.getBudgetDocument()
130: .getBudget().getModularBudget();
131:
132: this .load(mapping, budgetForm, request, response);
133: budgetForm.getBudgetDocument().getBudget().setModularBudget(
134: modular);
135:
136: SpringContext.getBean(BudgetModularService.class)
137: .generateModularBudget(
138: budgetForm.getBudgetDocument().getBudget(),
139: budgetForm.getNonpersonnelCategories());
140: return mapping.findForward(KFSConstants.MAPPING_BASIC);
141: }
142:
143: /**
144: * Reload from the database & recalculate all derived values.
145: *
146: * @param mapping
147: * @param form
148: * @param request
149: * @param response
150: * @throws Exception
151: */
152: public ActionForward reload(ActionMapping mapping, ActionForm form,
153: HttpServletRequest request, HttpServletResponse response)
154: throws Exception {
155: super .reload(mapping, form, request, response);
156: BudgetForm budgetForm = (BudgetForm) form;
157:
158: SpringContext.getBean(BudgetModularService.class)
159: .generateModularBudget(
160: budgetForm.getBudgetDocument().getBudget(),
161: budgetForm.getNonpersonnelCategories());
162: SpringContext.getBean(KualiRuleService.class).applyRules(
163: new EnterModularEvent(budgetForm.getDocument()));
164:
165: return mapping.findForward(KFSConstants.MAPPING_BASIC);
166: }
167: }
|