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 javax.servlet.http.HttpServletRequest; |
20 | |
import javax.servlet.http.HttpServletResponse; |
21 | |
|
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.apache.struts.action.ActionForm; |
24 | |
import org.apache.struts.action.ActionForward; |
25 | |
import org.apache.struts.action.ActionMapping; |
26 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
27 | |
import org.kuali.rice.kew.doctype.SecuritySession; |
28 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
29 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
30 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
31 | |
import org.kuali.rice.kew.routeheader.service.RouteHeaderService; |
32 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
33 | |
import org.kuali.rice.kew.util.KEWConstants; |
34 | |
import org.kuali.rice.kew.web.KewKualiAction; |
35 | |
import org.kuali.rice.krad.UserSession; |
36 | |
import org.kuali.rice.krad.util.GlobalVariables; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class ClientAppDocHandlerRedirectAction extends KewKualiAction { |
46 | |
|
47 | |
@Override |
48 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
49 | 0 | DocHandlerForm docHandlerForm = (DocHandlerForm) form; |
50 | |
|
51 | 0 | String docHandler = null; |
52 | |
|
53 | 0 | if (request.getParameter(KEWConstants.DOCUMENT_ID_PARAMETER) != null) { |
54 | 0 | RouteHeaderService rhSrv = (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV); |
55 | 0 | DocumentRouteHeaderValue routeHeader = rhSrv.getRouteHeader(docHandlerForm.getDocId()); |
56 | |
|
57 | 0 | if (!KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(GlobalVariables.getUserSession(), routeHeader, new SecuritySession(GlobalVariables.getUserSession()))) { |
58 | 0 | return mapping.findForward("NotAuthorized"); |
59 | |
} |
60 | 0 | docHandler = routeHeader.getDocumentType().getDocHandlerUrl(); |
61 | 0 | if (StringUtils.isBlank(docHandler)) { |
62 | 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.getDocumentId() + ")"); |
63 | |
} |
64 | 0 | if (!docHandler.contains("?")) { |
65 | 0 | docHandler += "?"; |
66 | |
} else { |
67 | 0 | docHandler += "&"; |
68 | |
} |
69 | 0 | docHandler += KEWConstants.DOCUMENT_ID_PARAMETER + "=" + docHandlerForm.getDocId(); |
70 | 0 | } else if (request.getParameter(KEWConstants.DOCTYPE_PARAMETER) != null) { |
71 | 0 | DocumentTypeService documentTypeService = (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE); |
72 | 0 | DocumentType documentType = documentTypeService.findByName(docHandlerForm.getDocTypeName()); |
73 | 0 | docHandler = documentType.getDocHandlerUrl(); |
74 | 0 | if (StringUtils.isBlank(docHandler)) { |
75 | 0 | throw new WorkflowRuntimeException("Cannot find document handler url for document type '" + documentType.getName() + "'"); |
76 | |
} |
77 | 0 | if (!docHandler.contains("?")) { |
78 | 0 | docHandler += "?"; |
79 | |
} else { |
80 | 0 | docHandler += "&"; |
81 | |
} |
82 | 0 | docHandler += KEWConstants.DOCTYPE_PARAMETER + "=" + docHandlerForm.getDocTypeName(); |
83 | 0 | } else { |
84 | |
|
85 | 0 | throw new RuntimeException ("Cannot determine document handler"); |
86 | |
} |
87 | |
|
88 | 0 | docHandler += "&" + KEWConstants.COMMAND_PARAMETER + "=" + docHandlerForm.getCommand(); |
89 | 0 | if (getUserSession(request).isBackdoorInUse()) { |
90 | 0 | docHandler += "&" + KEWConstants.BACKDOOR_ID_PARAMETER + "=" + getUserSession(request).getPrincipalName(); |
91 | |
} |
92 | 0 | return new ActionForward(docHandler, true); |
93 | |
} |
94 | |
|
95 | |
public static UserSession getUserSession(HttpServletRequest request) { |
96 | 0 | return GlobalVariables.getUserSession(); |
97 | |
} |
98 | |
} |