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