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.web.struts.action;
017:
018: import java.util.HashMap;
019:
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022:
023: import org.apache.commons.lang.StringUtils;
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.bo.AdHocRoutePerson;
028: import org.kuali.core.bo.AdHocRouteWorkgroup;
029: import org.kuali.core.bo.user.AuthenticationUserId;
030: import org.kuali.core.bo.user.UniversalUser;
031: import org.kuali.core.document.authorization.DocumentActionFlags;
032: import org.kuali.core.rule.event.AddAdHocRoutePersonEvent;
033: import org.kuali.core.rule.event.AddAdHocRouteWorkgroupEvent;
034: import org.kuali.core.service.DateTimeService;
035: import org.kuali.core.service.KualiRuleService;
036: import org.kuali.core.service.UniversalUserService;
037: import org.kuali.core.service.WebAuthenticationService;
038: import org.kuali.core.util.GlobalVariables;
039: import org.kuali.core.web.struts.action.KualiDocumentActionBase;
040: import org.kuali.core.web.struts.form.KualiForm;
041: import org.kuali.kfs.KFSConstants;
042: import org.kuali.kfs.context.SpringContext;
043: import org.kuali.module.kra.KraConstants;
044: import org.kuali.module.kra.KraKeyConstants;
045: import org.kuali.module.kra.bo.AdhocOrg;
046: import org.kuali.module.kra.bo.AdhocPerson;
047: import org.kuali.module.kra.bo.AdhocWorkgroup;
048: import org.kuali.module.kra.document.ResearchDocument;
049: import org.kuali.module.kra.web.struts.form.ResearchDocumentFormBase;
050:
051: import edu.iu.uis.eden.clientapp.IDocHandler;
052:
053: public abstract class ResearchDocumentActionBase extends
054: KualiDocumentActionBase {
055:
056: public ResearchDocumentActionBase() {
057: // TODO Auto-generated constructor stub
058: }
059:
060: /**
061: * This method will load the document, which was previously saved
062: *
063: * @param mapping
064: * @param form
065: * @param request
066: * @param response
067: * @return
068: * @throws Exception
069: */
070: public ActionForward load(ActionMapping mapping, ActionForm form,
071: HttpServletRequest request, HttpServletResponse response)
072: throws Exception {
073:
074: ResearchDocumentFormBase researchForm = (ResearchDocumentFormBase) form;
075: researchForm.setDocId(researchForm.getDocument()
076: .getDocumentNumber());
077: super .loadDocument(researchForm);
078:
079: return mapping.findForward(KFSConstants.MAPPING_BASIC);
080: }
081:
082: @Override
083: /**
084: * Overriding headerTab to customize how clearing tab state works on Budget. Specifically, additional attributes (selected task
085: * and period) should be cleared any time header navigation occurs.
086: */
087: public ActionForward headerTab(ActionMapping mapping,
088: ActionForm form, HttpServletRequest request,
089: HttpServletResponse response) throws Exception {
090:
091: ((KualiForm) form).setTabStates(new HashMap());
092:
093: return super .headerTab(mapping, form, request, response);
094: }
095:
096: public ActionForward docHandler(ActionMapping mapping,
097: ActionForm form, HttpServletRequest request,
098: HttpServletResponse response) throws Exception {
099:
100: ActionForward forward = super .docHandler(mapping, form,
101: request, response);
102: ResearchDocumentFormBase researchForm = (ResearchDocumentFormBase) form;
103:
104: if (IDocHandler.INITIATE_COMMAND.equals(researchForm
105: .getCommand())) {
106: // do something?
107: researchForm.getResearchDocument().initialize();
108: }
109: return forward;
110: }
111:
112: public ActionForward notes(ActionMapping mapping, ActionForm form,
113: HttpServletRequest request, HttpServletResponse response)
114: throws Exception {
115:
116: this .load(mapping, form, request, response);
117:
118: ResearchDocumentFormBase researchDocumentForm = (ResearchDocumentFormBase) form;
119:
120: if (researchDocumentForm.getDocument().getDocumentHeader()
121: .isBoNotesSupport()
122: && (researchDocumentForm.getDocument()
123: .getDocumentHeader().getBoNotes() == null || researchDocumentForm
124: .getDocument().getDocumentHeader().getBoNotes()
125: .isEmpty())) {
126: researchDocumentForm.getDocument().refreshReferenceObject(
127: "documentHeader");
128: }
129:
130: researchDocumentForm.setTabStates(new HashMap());
131:
132: return mapping.findForward("notes");
133: }
134:
135: @Override
136: public ActionForward insertAdHocRoutePerson(ActionMapping mapping,
137: ActionForm form, HttpServletRequest request,
138: HttpServletResponse response) throws Exception {
139: ResearchDocumentFormBase researchForm = (ResearchDocumentFormBase) form;
140: ResearchDocument researchDocument = (ResearchDocument) researchForm
141: .getDocument();
142:
143: // check authorization
144: DocumentActionFlags flags = getDocumentActionFlags(researchDocument);
145: if (!flags.getCanAdHocRoute()) {
146: throw buildAuthorizationException("ad-hoc route",
147: researchDocument);
148: }
149:
150: AdHocRoutePerson adHocRoutePerson = (AdHocRoutePerson) researchForm
151: .getNewAdHocRoutePerson();
152:
153: // check business rules
154: boolean rulePassed = SpringContext.getBean(
155: KualiRuleService.class).applyRules(
156: new AddAdHocRoutePersonEvent(researchDocument,
157: (AdHocRoutePerson) researchForm
158: .getNewAdHocRoutePerson()));
159:
160: if (rulePassed) {
161: AdhocPerson newAdHocPermission = researchForm
162: .getNewAdHocPerson();
163: UniversalUser user = SpringContext.getBean(
164: UniversalUserService.class).getUniversalUser(
165: new AuthenticationUserId(adHocRoutePerson.getId()));
166: newAdHocPermission.setPersonUniversalIdentifier(user
167: .getPersonUniversalIdentifier());
168: user.setPersonUserIdentifier(StringUtils.upperCase(user
169: .getPersonUserIdentifier()));
170: if (adHocRoutePerson.getActionRequested() == null
171: || StringUtils.isBlank(adHocRoutePerson
172: .getActionRequested())) {
173: newAdHocPermission
174: .setAdhocTypeCode(KraConstants.AD_HOC_PERMISSION);
175: } else {
176: newAdHocPermission.setActionRequested(adHocRoutePerson
177: .getActionRequested());
178: newAdHocPermission
179: .setAdhocTypeCode(KraConstants.AD_HOC_APPROVER);
180: }
181: newAdHocPermission.setUser(user);
182: newAdHocPermission.setPersonAddedTimestamp(SpringContext
183: .getBean(DateTimeService.class)
184: .getCurrentTimestamp());
185: newAdHocPermission.setAddedByPerson(SpringContext.getBean(
186: WebAuthenticationService.class).getNetworkId(
187: request));
188: researchDocument.getAdhocPersons().add(newAdHocPermission);
189: researchForm.setNewAdHocPerson(new AdhocPerson());
190: researchForm.setNewAdHocRoutePerson(new AdHocRoutePerson());
191: }
192:
193: return mapping.findForward(KFSConstants.MAPPING_BASIC);
194: }
195:
196: @Override
197: public ActionForward insertAdHocRouteWorkgroup(
198: ActionMapping mapping, ActionForm form,
199: HttpServletRequest request, HttpServletResponse response)
200: throws Exception {
201: ResearchDocumentFormBase researchForm = (ResearchDocumentFormBase) form;
202: ResearchDocument researchDocument = (ResearchDocument) researchForm
203: .getDocument();
204:
205: // check authorization
206: DocumentActionFlags flags = getDocumentActionFlags(researchDocument);
207: if (!flags.getCanAdHocRoute()) {
208: throw buildAuthorizationException("ad-hoc route",
209: researchDocument);
210: }
211:
212: AdHocRouteWorkgroup adHocRouteWorkgroup = (AdHocRouteWorkgroup) researchForm
213: .getNewAdHocRouteWorkgroup();
214:
215: // check business rules
216: boolean rulePassed = SpringContext.getBean(
217: KualiRuleService.class).applyRules(
218: new AddAdHocRouteWorkgroupEvent(researchDocument,
219: (AdHocRouteWorkgroup) researchForm
220: .getNewAdHocRouteWorkgroup()));
221:
222: if (rulePassed) {
223: AdhocWorkgroup newAdHocWorkgroup = new AdhocWorkgroup(
224: adHocRouteWorkgroup.getId());
225: if (adHocRouteWorkgroup.getActionRequested() == null) {
226: newAdHocWorkgroup
227: .setAdhocTypeCode(KraConstants.AD_HOC_PERMISSION);
228: } else {
229: newAdHocWorkgroup
230: .setActionRequested(adHocRouteWorkgroup
231: .getActionRequested());
232: newAdHocWorkgroup
233: .setAdhocTypeCode(KraConstants.AD_HOC_APPROVER);
234: }
235: newAdHocWorkgroup.setPermissionCode(researchForm
236: .getNewAdHocWorkgroupPermissionCode());
237: newAdHocWorkgroup.setPersonAddedTimestamp(SpringContext
238: .getBean(DateTimeService.class)
239: .getCurrentTimestamp());
240: newAdHocWorkgroup.setAddedByPerson(SpringContext.getBean(
241: WebAuthenticationService.class).getNetworkId(
242: request));
243: researchDocument.getAdhocWorkgroups()
244: .add(newAdHocWorkgroup);
245: researchForm
246: .setNewAdHocRouteWorkgroup(new AdHocRouteWorkgroup());
247: }
248:
249: return mapping.findForward(KFSConstants.MAPPING_BASIC);
250: }
251:
252: /**
253: * This method will remove the selected ad-hoc person from the list.
254: *
255: * @param mapping
256: * @param form
257: * @param request
258: * @param response
259: * @return ActionForward
260: * @throws Exception
261: */
262: public ActionForward delete(ActionMapping mapping, ActionForm form,
263: HttpServletRequest request, HttpServletResponse response)
264: throws Exception {
265:
266: ResearchDocumentFormBase researchForm = (ResearchDocumentFormBase) form;
267: ResearchDocument researchDocument = (ResearchDocument) researchForm
268: .getDocument();
269: researchDocument.getAdhocPersons().remove(
270: getLineToDelete(request));
271:
272: return mapping.findForward(KFSConstants.MAPPING_BASIC);
273: }
274:
275: /**
276: * This method will remove the selected ad-hoc person from the list.
277: *
278: * @param mapping
279: * @param form
280: * @param request
281: * @param response
282: * @return ActionForward
283: * @throws Exception
284: */
285: public ActionForward deleteWorkgroup(ActionMapping mapping,
286: ActionForm form, HttpServletRequest request,
287: HttpServletResponse response) throws Exception {
288:
289: ResearchDocumentFormBase researchForm = (ResearchDocumentFormBase) form;
290: ResearchDocument researchDocument = (ResearchDocument) researchForm
291: .getDocument();
292: researchDocument.getAdhocWorkgroups().remove(
293: getLineToDelete(request));
294:
295: return mapping.findForward(KFSConstants.MAPPING_BASIC);
296: }
297:
298: /**
299: * This method will add a new ad-hoc org to the list.
300: *
301: * @param mapping
302: * @param form
303: * @param request
304: * @param response
305: * @return ActionForward
306: * @throws Exception
307: */
308: public ActionForward addOrg(ActionMapping mapping, ActionForm form,
309: HttpServletRequest request, HttpServletResponse response)
310: throws Exception {
311:
312: ResearchDocumentFormBase researchForm = (ResearchDocumentFormBase) form;
313: ResearchDocument researchDocument = (ResearchDocument) researchForm
314: .getDocument();
315:
316: if (researchForm.getNewAdHocOrg().getFiscalCampusCode() == null) {
317: // Add page error.
318: GlobalVariables.getErrorMap().putError("newAdHocOrg",
319: KraKeyConstants.ERROR_NO_ORG_SELECTED,
320: new String[] {});
321: } else {
322: AdhocOrg newAdHocOrg = researchForm.getNewAdHocOrg();
323: if (newAdHocOrg.getActionRequested() == null) {
324: newAdHocOrg
325: .setAdhocTypeCode(KraConstants.AD_HOC_PERMISSION);
326: } else {
327: newAdHocOrg
328: .setAdhocTypeCode(KraConstants.AD_HOC_APPROVER);
329: }
330: newAdHocOrg.setPersonAddedTimestamp(SpringContext.getBean(
331: DateTimeService.class).getCurrentTimestamp());
332: newAdHocOrg.setAddedByPerson(SpringContext.getBean(
333: WebAuthenticationService.class).getNetworkId(
334: request));
335: researchDocument.getAdhocOrgs().add(newAdHocOrg);
336: researchForm.setNewAdHocOrg(new AdhocOrg());
337: }
338:
339: return mapping.findForward(KFSConstants.MAPPING_BASIC);
340: }
341:
342: /**
343: * This method will remove the selected ad-hoc org from the list.
344: *
345: * @param mapping
346: * @param form
347: * @param request
348: * @param response
349: * @return ActionForward
350: * @throws Exception
351: */
352: public ActionForward deleteOrg(ActionMapping mapping,
353: ActionForm form, HttpServletRequest request,
354: HttpServletResponse response) throws Exception {
355:
356: ResearchDocumentFormBase researchForm = (ResearchDocumentFormBase) form;
357: ResearchDocument researchDocument = (ResearchDocument) researchForm
358: .getDocument();
359: researchDocument.getAdhocOrgs()
360: .remove(getLineToDelete(request));
361:
362: return mapping.findForward(KFSConstants.MAPPING_BASIC);
363: }
364: }
|