1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.routing.web; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.apache.struts.action.ActionForm; |
21 | |
import org.apache.struts.action.ActionForward; |
22 | |
import org.apache.struts.action.ActionMapping; |
23 | |
import org.kuali.rice.kew.doctype.SecuritySession; |
24 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
25 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
26 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
27 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
28 | |
import org.kuali.rice.kew.routeheader.service.RouteHeaderService; |
29 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
30 | |
import org.kuali.rice.kew.util.KEWConstants; |
31 | |
import org.kuali.rice.kew.web.KewKualiAction; |
32 | |
import org.kuali.rice.kew.web.session.UserSession; |
33 | |
|
34 | |
import javax.servlet.http.HttpServletRequest; |
35 | |
import javax.servlet.http.HttpServletResponse; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class ClientAppDocHandlerRedirectAction extends KewKualiAction { |
45 | |
|
46 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
47 | 0 | DocHandlerForm docHandlerForm = (DocHandlerForm) form; |
48 | |
|
49 | 0 | String docHandler = null; |
50 | |
|
51 | 0 | if (request.getParameter(KEWConstants.ROUTEHEADER_ID_PARAMETER) != null) { |
52 | 0 | RouteHeaderService rhSrv = (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV); |
53 | 0 | DocumentRouteHeaderValue routeHeader = rhSrv.getRouteHeader(docHandlerForm.getDocId()); |
54 | |
|
55 | 0 | if (!KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(UserSession.getAuthenticatedUser(), routeHeader, new SecuritySession(UserSession.getAuthenticatedUser()))) { |
56 | 0 | return mapping.findForward("NotAuthorized"); |
57 | |
} |
58 | 0 | docHandler = routeHeader.getDocumentType().getDocHandlerUrl(); |
59 | 0 | if (StringUtils.isBlank(docHandler)) { |
60 | 0 | throw new WorkflowRuntimeException("Document Type '" + routeHeader.getDocumentType().getName() + "' does not have a document handler url set (attempted to open document handler url for document id " + routeHeader.getRouteHeaderId() + ")"); |
61 | |
} |
62 | 0 | if (!docHandler.contains("?")) { |
63 | 0 | docHandler += "?"; |
64 | |
} else { |
65 | 0 | docHandler += "&"; |
66 | |
} |
67 | 0 | docHandler += KEWConstants.ROUTEHEADER_ID_PARAMETER + "=" + docHandlerForm.getDocId(); |
68 | 0 | } else if (request.getParameter(KEWConstants.DOCTYPE_PARAMETER) != null) { |
69 | 0 | DocumentTypeService documentTypeService = (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE); |
70 | 0 | DocumentType documentType = documentTypeService.findByName(docHandlerForm.getDocTypeName()); |
71 | 0 | docHandler = documentType.getDocHandlerUrl(); |
72 | 0 | if (StringUtils.isBlank(docHandler)) { |
73 | 0 | throw new WorkflowRuntimeException("Cannot find document handler url for document type '" + documentType.getName() + "'"); |
74 | |
} |
75 | 0 | if (!docHandler.contains("?")) { |
76 | 0 | docHandler += "?"; |
77 | |
} else { |
78 | 0 | docHandler += "&"; |
79 | |
} |
80 | 0 | docHandler += KEWConstants.DOCTYPE_PARAMETER + "=" + docHandlerForm.getDocTypeName(); |
81 | 0 | } else { |
82 | |
|
83 | 0 | throw new RuntimeException ("Cannot determine document handler"); |
84 | |
} |
85 | |
|
86 | 0 | docHandler += "&" + KEWConstants.COMMAND_PARAMETER + "=" + docHandlerForm.getCommand(); |
87 | 0 | if (getUserSession(request).isBackdoorInUse()) { |
88 | 0 | docHandler += "&" + KEWConstants.BACKDOOR_ID_PARAMETER + "=" + getUserSession(request).getPrincipalName(); |
89 | |
} |
90 | 0 | return new ActionForward(docHandler, true); |
91 | |
} |
92 | |
|
93 | |
public static UserSession getUserSession(HttpServletRequest request) { |
94 | 0 | return UserSession.getAuthenticatedUser(); |
95 | |
} |
96 | |
} |