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