1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.edl;
18
19 import java.io.IOException;
20
21 import javax.servlet.RequestDispatcher;
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServlet;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.log4j.Logger;
29 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
30 import org.kuali.rice.kew.service.KEWServiceLocator;
31 import org.kuali.rice.kew.web.session.UserSession;
32 import org.kuali.rice.kns.util.IncidentReportUtils;
33 import org.kuali.rice.kns.util.KNSConstants;
34 import org.w3c.dom.Document;
35 import org.w3c.dom.Element;
36
37
38
39
40
41
42
43
44 public class EDLServlet extends HttpServlet {
45
46 private static final long serialVersionUID = -6344765194278430690L;
47
48 private static final Logger LOG = Logger.getLogger(EDLServlet.class);
49
50 public void init() throws ServletException {
51 try {
52 KEWServiceLocator.getEDocLiteService().initEDLGlobalConfig();
53 } catch (Exception e) {
54 LOG.error("Error initializing EDL", e);
55 }
56
57 }
58
59 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
60 String documentId = null;
61 try {
62 RequestParser requestParser = new RequestParser(request);
63 String inputCommand = requestParser.getParameterValue("command");
64 if (StringUtils.equals(inputCommand, "initiate")){
65 requestParser.setParameterValue("userAction","initiate");
66 }
67 String edlName = requestParser.getParameterValue("edlName");
68 if (edlName == null) {
69 edlName = requestParser.getParameterValue("docTypeName");
70 }
71 EDLController edlController = null;
72
73 if (edlName == null) {
74 documentId = requestParser.getParameterValue("docId");
75 if (documentId == null) {
76 String docFormKey = requestParser.getParameterValue(KNSConstants.DOC_FORM_KEY);
77 if (docFormKey != null) {
78 Document document = (Document) UserSession.getAuthenticatedUser().retrieveObject(docFormKey);
79 Element documentState = EDLXmlUtils.getDocumentStateElement(document);
80 documentId = EDLXmlUtils.getChildElementTextValue(documentState, "docId");
81 requestParser.setAttribute(KNSConstants.DOC_FORM_KEY, docFormKey);
82 }
83 if (documentId == null) {
84 throw new WorkflowRuntimeException("No edl name or document id detected");
85 }
86 }
87 requestParser.setAttribute("docId", documentId);
88 edlController = KEWServiceLocator.getEDocLiteService().getEDLController(new Long(documentId));
89 } else {
90 edlController = KEWServiceLocator.getEDocLiteService().getEDLController(edlName);
91 }
92
93
94
95 if(inputCommand == null && requestParser.getParameterValue("docId") != null && !"POST".equals(request.getMethod())){
96
97 if(!(request.getParameterMap().size() > 2)){
98 requestParser.setParameterValue("command", "displayDocSearchView");
99 LOG.info("command parameter was not passed with the request, and only document ID was. Defaulted command to 'displayDocSearchView' to ensure docContent remains.");
100 }
101 }
102
103 EDLControllerChain controllerChain = new EDLControllerChain();
104 controllerChain.addEdlController(edlController);
105
106 controllerChain.renderEDL(requestParser, response);
107
108 } catch (Exception e) {
109 LOG.error("Error processing EDL", e);
110 outputError(request, response, e, documentId);
111 }
112 }
113
114 private void outputError(HttpServletRequest request, HttpServletResponse response, Exception exception, String documentId) throws ServletException, IOException {
115 IncidentReportUtils.populateRequestForIncidentReport(exception, ""+documentId, "eDoc Lite", request);
116 RequestDispatcher rd = getServletContext().getRequestDispatcher(request.getServletPath() + "/../../kr/kualiExceptionIncidentReport.do");
117 rd.forward(request, response);
118 }
119
120 }