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.superuser.web;
018:
019: import java.util.Collection;
020: import java.util.Iterator;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.apache.struts.action.ActionForm;
026: import org.apache.struts.action.ActionForward;
027: import org.apache.struts.action.ActionMapping;
028: import org.apache.struts.action.ActionMessage;
029: import org.apache.struts.action.ActionMessages;
030: import org.kuali.rice.resourceloader.GlobalResourceLoader;
031:
032: import edu.iu.uis.eden.EdenConstants;
033: import edu.iu.uis.eden.KEWServiceLocator;
034: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
035: import edu.iu.uis.eden.clientapp.IDocHandler;
036: import edu.iu.uis.eden.clientapp.WorkflowDocument;
037: import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
038: import edu.iu.uis.eden.plugin.attributes.WorkflowLookupable;
039: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
040: import edu.iu.uis.eden.user.WorkflowUser;
041: import edu.iu.uis.eden.web.WorkflowAction;
042:
043: /**
044: * A Struts Action which provides super user functionality.
045: *
046: * @author bmcgough
047: * @author xqi
048: * @author temay
049: * @author rkirkend
050: */
051: public class SuperUserAction extends WorkflowAction {
052: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
053: .getLogger(SuperUserAction.class);
054: public static final String UNAUTHORIZED = "authorizationFailure";
055:
056: //private static String DOCUMENT_TYPE = "EDENSERVICE-DOCS.WKGRPREQ";
057:
058: public ActionForward start(ActionMapping mapping, ActionForm form,
059: HttpServletRequest request, HttpServletResponse response)
060: throws Exception {
061: return mapping.findForward("basic");
062: }
063:
064: public ActionForward displaySuperUserDocument(
065: ActionMapping mapping, ActionForm form,
066: HttpServletRequest request, HttpServletResponse response)
067: throws Exception {
068: SuperUserForm super UserForm = (SuperUserForm) form;
069: super UserForm
070: .setDocHandlerUrl(EdenConstants.DOC_HANDLER_REDIRECT_PAGE
071: + "?docId="
072: + super UserForm.getRouteHeaderId()
073: + "&"
074: + IDocHandler.COMMAND_PARAMETER
075: + "="
076: + IDocHandler.SUPERUSER_COMMAND);
077: return mapping.findForward("basic");
078: }
079:
080: public ActionForward routeLevelApprove(ActionMapping mapping,
081: ActionForm form, HttpServletRequest request,
082: HttpServletResponse response) throws Exception {
083: LOG.info("entering routeLevelApprove()...");
084: SuperUserForm super UserForm = (SuperUserForm) form;
085: //SpringServiceLocator.getWorkflowDocumentService().superUserRouteLevelApproveAction(getUserSession(request).getWorkflowUser(), superUserForm.getRouteHeader(), superUserForm.getRouteLevel(), superUserForm.getAnnotation());
086: KEWServiceLocator.getWorkflowDocumentService()
087: .super UserNodeApproveAction(
088: getUserSession(request).getWorkflowUser(),
089: super UserForm.getRouteHeader(),
090: super UserForm.getDestNodeName(),
091: super UserForm.getAnnotation());
092: saveDocumentActionMessage(
093: "general.routing.superuser.routeLevelApproved",
094: request, super UserForm.getRouteHeaderIdString(), null);
095: LOG.info("exiting routeLevelApprove()...");
096: super UserForm.getActionRequests().clear();
097: establishRequiredState(request, form);
098: return mapping.findForward("basic");
099: }
100:
101: public ActionForward approve(ActionMapping mapping,
102: ActionForm form, HttpServletRequest request,
103: HttpServletResponse response) throws Exception {
104: LOG.info("entering approve() ...");
105: SuperUserForm super UserForm = (SuperUserForm) form;
106: KEWServiceLocator.getWorkflowDocumentService()
107: .super UserApprove(
108: getUserSession(request).getWorkflowUser(),
109: super UserForm.getRouteHeader(),
110: super UserForm.getAnnotation());
111: saveDocumentActionMessage("general.routing.superuser.approved",
112: request, super UserForm.getRouteHeaderIdString(), null);
113: LOG.info("exiting approve() ...");
114: super UserForm.getActionRequests().clear();
115: establishRequiredState(request, form);
116: return mapping.findForward("basic");
117: }
118:
119: public ActionForward disapprove(ActionMapping mapping,
120: ActionForm form, HttpServletRequest request,
121: HttpServletResponse response) throws Exception {
122: LOG.info("entering disapprove() ...");
123: SuperUserForm super UserForm = (SuperUserForm) form;
124: KEWServiceLocator.getWorkflowDocumentService()
125: .super UserDisapproveAction(
126: getUserSession(request).getWorkflowUser(),
127: super UserForm.getRouteHeader(),
128: super UserForm.getAnnotation());
129: saveDocumentActionMessage(
130: "general.routing.superuser.disapproved", request,
131: super UserForm.getRouteHeaderIdString(), null);
132: LOG.info("exiting disapprove() ...");
133: super UserForm.getActionRequests().clear();
134: establishRequiredState(request, form);
135: return mapping.findForward("basic");
136: }
137:
138: public ActionForward cancel(ActionMapping mapping, ActionForm form,
139: HttpServletRequest request, HttpServletResponse response)
140: throws Exception {
141: LOG.info("entering cancel() ...");
142: SuperUserForm super UserForm = (SuperUserForm) form;
143: KEWServiceLocator.getWorkflowDocumentService()
144: .super UserCancelAction(
145: getUserSession(request).getWorkflowUser(),
146: super UserForm.getRouteHeader(),
147: super UserForm.getAnnotation());
148: saveDocumentActionMessage("general.routing.superuser.canceled",
149: request, super UserForm.getRouteHeaderIdString(), null);
150: LOG.info("exiting cancel() ...");
151: super UserForm.getActionRequests().clear();
152: establishRequiredState(request, form);
153: return mapping.findForward("basic");
154: }
155:
156: public ActionForward returnToPreviousNode(ActionMapping mapping,
157: ActionForm form, HttpServletRequest request,
158: HttpServletResponse response) throws Exception {
159: LOG.info("entering returnToPreviousNode() ...");
160: SuperUserForm super UserForm = (SuperUserForm) form;
161: KEWServiceLocator.getWorkflowDocumentService()
162: .super UserReturnDocumentToPreviousNode(
163: getUserSession(request).getWorkflowUser(),
164: super UserForm.getRouteHeaderId(),
165: super UserForm.getReturnDestNodeName(),
166: super UserForm.getAnnotation());
167: saveDocumentActionMessage(
168: "general.routing.returnedToPreviousNode", request,
169: "document", super UserForm.getReturnDestNodeName()
170: .toString());
171: LOG.info("exiting returnToPreviousRouteLevel() ...");
172: super UserForm.getActionRequests().clear();
173: establishRequiredState(request, form);
174: return mapping.findForward("basic");
175: }
176:
177: public ActionForward actionRequestApprove(ActionMapping mapping,
178: ActionForm form, HttpServletRequest request,
179: HttpServletResponse response) throws Exception {
180: LOG.info("entering actionRequestApprove() ...");
181: SuperUserForm super UserForm = (SuperUserForm) form;
182: LOG.debug("Routing super user action request approve action");
183: KEWServiceLocator.getWorkflowDocumentService()
184: .super UserActionRequestApproveAction(
185: getUserSession(request).getWorkflowUser(),
186: super UserForm.getRouteHeader(),
187: new Long(super UserForm
188: .getActionTakenActionRequestId()),
189: super UserForm.getAnnotation());
190: String messageString;
191: String actionReqest = (String) request
192: .getParameter("buttonClick");
193: if (actionReqest.equalsIgnoreCase("acknowlege")) {
194: messageString = "general.routing.superuser.actionRequestAcknowleged";
195: } else if (actionReqest.equalsIgnoreCase("FYI")) {
196: messageString = "general.routing.superuser.actionRequestFYI";
197: } else if (actionReqest.equalsIgnoreCase("complete")) {
198: messageString = "general.routing.superuser.actionRequestCompleted";
199: } else if (actionReqest.equalsIgnoreCase("approved")) {
200: messageString = "general.routing.superuser.actionRequestApproved";
201: } else {
202: messageString = "general.routing.superuser.actionRequestApproved";
203: }
204: saveDocumentActionMessage(messageString, request, super UserForm
205: .getRouteHeaderIdString(), super UserForm
206: .getActionTakenActionRequestId());
207: LOG.info("exiting actionRequestApprove() ...");
208: super UserForm.getActionRequests().clear();
209: establishRequiredState(request, form);
210: return mapping.findForward("basic");
211: }
212:
213: public ActionMessages establishRequiredState(
214: HttpServletRequest request, ActionForm form)
215: throws Exception {
216: SuperUserForm super UserForm = (SuperUserForm) form;
217: DocumentRouteHeaderValue routeHeader = KEWServiceLocator
218: .getRouteHeaderService().getRouteHeader(
219: super UserForm.getRouteHeaderId());
220: super UserForm.setRouteHeader(routeHeader);
221: WorkflowUser user = getUserSession(request).getWorkflowUser();
222: boolean isAuthorized = routeHeader.getDocumentType()
223: .isSuperUser(user);
224: super UserForm.setAuthorized(isAuthorized);
225: if (!isAuthorized) {
226: saveDocumentActionMessage(
227: "general.routing.superuser.notAuthorized", request,
228: super UserForm.getRouteHeaderIdString(), null);
229: return null;
230: }
231:
232: super UserForm.setFutureNodeNames(KEWServiceLocator
233: .getRouteNodeService().findFutureNodeNames(
234: routeHeader.getRouteHeaderId()));
235:
236: Collection actionRequests = KEWServiceLocator
237: .getActionRequestService().findPendingByDoc(
238: routeHeader.getRouteHeaderId());
239: Iterator requestIterator = actionRequests.iterator();
240: while (requestIterator.hasNext()) {
241: ActionRequestValue req = (ActionRequestValue) requestIterator
242: .next();
243: // if (EdenConstants.ACTION_REQUEST_APPROVE_REQ.equalsIgnoreCase(req.getActionRequested())) {
244: super UserForm.getActionRequests().add(req);
245: // }
246: }
247:
248: super UserForm.setDocId(super UserForm.getRouteHeaderId());
249: if (super UserForm.getDocId() != null) {
250: super UserForm.setFlexDoc(new WorkflowDocument(
251: new WorkflowIdVO(getUserSession(request)
252: .getWorkflowUser().getWorkflowId()),
253: super UserForm.getDocId()));
254: super UserForm.establishVisibleActionRequestCds();
255: }
256:
257: return null;
258: }
259:
260: public void saveDocumentActionMessage(String messageKey,
261: HttpServletRequest request, String subVariable1,
262: String subVariable2) {
263: ActionMessages messages = new ActionMessages();
264: ActionMessage actionMessage = null;
265: if (subVariable2 == null) {
266: actionMessage = new ActionMessage(messageKey, subVariable1);
267: } else {
268: actionMessage = new ActionMessage(messageKey, subVariable1,
269: subVariable2);
270: }
271: messages.add(ActionMessages.GLOBAL_MESSAGE, actionMessage);
272: saveMessages(request, messages);
273: }
274:
275: public ActionForward performLookup(ActionMapping mapping,
276: ActionForm form, HttpServletRequest request,
277: HttpServletResponse response) throws Exception {
278: SuperUserForm super UserForm = (SuperUserForm) form;
279:
280: String basePath = request.getScheme() + "://"
281: + request.getServerName() + ":"
282: + request.getServerPort() + request.getContextPath()
283: + mapping.getModuleConfig().getPrefix();
284: StringBuffer lookupUrl = new StringBuffer(basePath);
285: lookupUrl.append("/Lookup.do?methodToCall=start&docFormKey=")
286: .append(getUserSession(request).addObject(form))
287: .append("&lookupableImplServiceName=");
288: lookupUrl.append(request
289: .getParameter("lookupableImplServiceName"));
290:
291: String lookupType = super UserForm.getLookupType();
292: super UserForm.setLookupType(null);
293:
294: if (lookupType != null && !lookupType.equals("")) {
295: lookupUrl.append("&conversionFields=");
296: WorkflowLookupable workflowLookupable = (WorkflowLookupable) GlobalResourceLoader
297: .getService(request
298: .getParameter("lookupableImplServiceName"));//SpringServiceLocator.getExtensionService().getLookupable(request.getParameter("lookupableImplServiceName"));
299: for (Iterator iterator = workflowLookupable
300: .getDefaultReturnType().iterator(); iterator
301: .hasNext();) {
302: String returnType = (String) iterator.next();
303: lookupUrl.append(returnType).append(":").append(
304: lookupType);
305: }
306: }
307:
308: lookupUrl.append("&returnLocation=").append(basePath).append(
309: mapping.getPath()).append(".do");
310: return new ActionForward(lookupUrl.toString(), true);
311: }
312:
313: public ActionForward routeToAppSpecificRecipient(
314: ActionMapping mapping, ActionForm form,
315: HttpServletRequest request, HttpServletResponse response)
316: throws Exception {
317: SuperUserForm super UserForm = (SuperUserForm) form;
318: super.routeToAppSpecificRecipient(mapping, form, request,
319: response);
320: superUserForm.getActionRequests().clear();
321: establishRequiredState(request, form);
322: return start(mapping, form, request, response);
323: }
324: }
|