001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routing.web;
018:
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import org.apache.struts.action.ActionForm;
023: import org.apache.struts.action.ActionForward;
024: import org.apache.struts.action.ActionMapping;
025: import org.apache.struts.action.ActionMessage;
026: import org.apache.struts.action.ActionMessages;
027:
028: import edu.iu.uis.eden.EdenConstants;
029: import edu.iu.uis.eden.clientapp.WorkflowDocument;
030: import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
031: import edu.iu.uis.eden.util.Utilities;
032: import edu.iu.uis.eden.web.WorkflowAction;
033:
034: /**
035: * A Struts Action which handles requests for the Doc Handler for all documents
036: * that are part of the core workflow system (i.e. Workgroup, Rules).
037: *
038: * @author rkirkend
039: * @author temay
040: */
041: public class WorkflowDocHandlerAction extends WorkflowAction {
042:
043: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
044: .getLogger(WorkflowDocHandlerAction.class);
045:
046: public ActionForward start(ActionMapping mapping, ActionForm form,
047: HttpServletRequest request, HttpServletResponse response)
048: throws Exception {
049: return null;
050: }
051:
052: public ActionForward blanketApprove(ActionMapping mapping,
053: ActionForm form, HttpServletRequest request,
054: HttpServletResponse response) throws Exception {
055: LOG.info("entering blanketApprove() method ...");
056: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
057: docHandlerForm.getFlexDoc().blanketApprove(
058: docHandlerForm.getAnnotation());
059: saveDocumentActionMessage("general.routing.blanketApproved",
060: request);
061: LOG.info("forwarding to actionTaken from blanketApprove()");
062: return mapping.findForward("actionTaken");
063: }
064:
065: public ActionForward approve(ActionMapping mapping,
066: ActionForm form, HttpServletRequest request,
067: HttpServletResponse response) throws Exception {
068: LOG.info("entering approve() method ...");
069: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
070: docHandlerForm.getFlexDoc().approve(
071: docHandlerForm.getAnnotation());
072: saveDocumentActionMessage("general.routing.approved", request);
073: LOG.info("forwarding to actionTaken from approve()");
074: return mapping.findForward("actionTaken");
075: }
076:
077: public ActionForward complete(ActionMapping mapping,
078: ActionForm form, HttpServletRequest request,
079: HttpServletResponse response) throws Exception {
080: LOG.info("entering complete() method ...");
081: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
082: docHandlerForm.getFlexDoc().complete(
083: docHandlerForm.getAnnotation());
084: saveDocumentActionMessage("general.routing.completed", request);
085: LOG.info("forwarding to actionTaken from complete()");
086: return mapping.findForward("actionTaken");
087: }
088:
089: public ActionForward disapprove(ActionMapping mapping,
090: ActionForm form, HttpServletRequest request,
091: HttpServletResponse response) throws Exception {
092: LOG.info("entering disapprove() method ...");
093: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
094: docHandlerForm.getFlexDoc().disapprove(
095: docHandlerForm.getAnnotation());
096: saveDocumentActionMessage("general.routing.disapproved",
097: request);
098: LOG.info("forwarding to actionTaken from disapprove()");
099: return mapping.findForward("actionTaken");
100: }
101:
102: /*public ActionForward returnToPreviousRouteLevel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
103: LOG.info("entering returnToPreviousRouteLevel method ...");
104: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
105: docHandlerForm.getFlexDoc().returnToPreviousRouteLevel(docHandlerForm.getAnnotation(), docHandlerForm.getDestRouteLevel());
106: saveDocumentActionMessage("general.routing.returnedToPreviousRouteLevel", request, docHandlerForm.getDestRouteLevel().toString());
107: LOG.info("forwarding to actionTaken from returnToPreviousRouteLevel()");
108: return mapping.findForward("actionTaken");
109: }*/
110:
111: public ActionForward cancel(ActionMapping mapping, ActionForm form,
112: HttpServletRequest request, HttpServletResponse response)
113: throws Exception {
114: LOG.info("entering cancel() method ...");
115: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
116: docHandlerForm.getFlexDoc().cancel(
117: docHandlerForm.getAnnotation());
118: saveDocumentActionMessage("general.routing.canceled", request);
119: LOG.info("forwarding to actionTaken from cancel()");
120: return mapping.findForward("actionTaken");
121: }
122:
123: public ActionForward fyi(ActionMapping mapping, ActionForm form,
124: HttpServletRequest request, HttpServletResponse response)
125: throws Exception {
126: LOG.info("entering fyi() method ...");
127: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
128: docHandlerForm.getFlexDoc().fyi();
129: saveDocumentActionMessage("general.routing.fyied", request);
130: LOG.info("forwarding to actionTaken from fyi()");
131: return mapping.findForward("actionTaken");
132: }
133:
134: public ActionForward acknowledge(ActionMapping mapping,
135: ActionForm form, HttpServletRequest request,
136: HttpServletResponse response) throws Exception {
137: LOG.info("entering acknowledge() method ...");
138: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
139: docHandlerForm.getFlexDoc().acknowledge(
140: docHandlerForm.getAnnotation());
141: saveDocumentActionMessage("general.routing.acknowledged",
142: request);
143: LOG.info("forwarding to actionTaken from acknowledge()");
144: return mapping.findForward("actionTaken");
145: }
146:
147: public void saveDocumentActionMessage(String messageKey,
148: HttpServletRequest request, String secondMessageParameter) {
149: ActionMessages messages = new ActionMessages();
150:
151: if (Utilities.isEmpty(secondMessageParameter)) {
152: messages.add(ActionMessages.GLOBAL_MESSAGE,
153: new ActionMessage(messageKey, "document"));
154: } else {
155: messages.add(ActionMessages.GLOBAL_MESSAGE,
156: new ActionMessage(messageKey, "document",
157: secondMessageParameter));
158: }
159: saveMessages(request, messages);
160: }
161:
162: public void saveDocumentActionMessage(String messageKey,
163: HttpServletRequest request) {
164: saveDocumentActionMessage(messageKey, request, null);
165: }
166:
167: public ActionMessages establishRequiredState(
168: HttpServletRequest request, ActionForm form)
169: throws Exception {
170: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
171: try {
172: WorkflowDocument flexDoc = new WorkflowDocument(
173: new WorkflowIdVO(getUserSession(request)
174: .getWorkflowUser().getWorkflowId()),
175: docHandlerForm.getDocId());
176: docHandlerForm.setFlexDoc(flexDoc);
177: } catch (Exception e) {
178: throw new RuntimeException(e);
179: }
180: return null;
181: }
182:
183: public ActionForward refresh(ActionMapping mapping,
184: ActionForm form, HttpServletRequest request,
185: HttpServletResponse response) throws Exception {
186: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
187: if (!Utilities.isEmpty(docHandlerForm
188: .getDocHandlerRedirectUrl())) {
189: StringBuffer url = new StringBuffer(docHandlerForm
190: .getDocHandlerRedirectUrl());
191:
192: if (request.getParameter("networkId") != null) {
193: url.append("&networkId=").append(
194: request.getParameter("networkId"));
195: } else if (request.getParameter("workgroupId") != null) {
196: url.append("&workgroupId=").append(
197: request.getParameter("workgroupId"));
198: }
199: url
200: .append("&appSpecificRouteActionRequestCd=")
201: .append(
202: docHandlerForm
203: .getAppSpecificRouteActionRequestCd());
204: return new ActionForward(url.toString(), true);
205: }
206: return mapping.findForward("actionTaken");
207: }
208:
209: public ActionForward performLookup(ActionMapping mapping,
210: ActionForm form, HttpServletRequest request,
211: HttpServletResponse response) throws Exception {
212: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
213: docHandlerForm.setDocHandlerRedirectUrl(request
214: .getParameter(EdenConstants.DOC_HANDLER_RETURN_URL));
215:
216: String basePath = request.getScheme() + "://"
217: + request.getServerName() + ":"
218: + request.getServerPort() + request.getContextPath()
219: + mapping.getModuleConfig().getPrefix();
220: StringBuffer lookupUrl = new StringBuffer(basePath);
221: lookupUrl.append("/Lookup.do?methodToCall=start&docFormKey=")
222: .append(getUserSession(request).addObject(form))
223: .append("&lookupableImplServiceName=");
224: lookupUrl.append(request
225: .getParameter("lookupableImplServiceName"));
226:
227: lookupUrl.append("&returnLocation=").append(basePath).append(
228: mapping.getPath()).append(".do");
229: return new ActionForward(lookupUrl.toString(), true);
230: }
231: }
|