Coverage Report - org.kuali.rice.edl.impl.EDLServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
EDLServlet
0%
0/51
0%
0/22
6
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.edl.impl;
 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.edl.impl.service.EdlServiceLocator;
 30  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 31  
 import org.kuali.rice.kns.util.IncidentReportUtils;
 32  
 import org.kuali.rice.krad.UserSession;
 33  
 import org.kuali.rice.krad.exception.AuthenticationException;
 34  
 import org.kuali.rice.krad.util.GlobalVariables;
 35  
 import org.kuali.rice.krad.util.KRADConstants;
 36  
 import org.kuali.rice.krad.util.KRADUtils;
 37  
 import org.w3c.dom.Document;
 38  
 import org.w3c.dom.Element;
 39  
 
 40  
 
 41  
 /**
 42  
  * Takes edl web requests.
 43  
  * 
 44  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 45  
  *
 46  
  */
 47  0
 public class EDLServlet extends HttpServlet {
 48  
 
 49  
         private static final long serialVersionUID = -6344765194278430690L;
 50  
 
 51  0
         private static final Logger LOG = Logger.getLogger(EDLServlet.class);
 52  
 
 53  
         @Override
 54  
         public void init() throws ServletException {
 55  
                 try {
 56  0
                         EdlServiceLocator.getEDocLiteService().initEDLGlobalConfig();
 57  0
                 } catch (Exception e) {
 58  0
                         LOG.error("Error initializing EDL", e);
 59  0
                 }
 60  
 
 61  0
         }
 62  
 
 63  
         @Override
 64  
         protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 65  0
                 String documentId = null;
 66  
                 try {
 67  0
                     UserSession userSession = KRADUtils.getUserSessionFromRequest(request);
 68  0
                     if (userSession == null) {
 69  0
                         throw new AuthenticationException("Failed to locate a user session for request.");
 70  
                     }
 71  0
                     GlobalVariables.setUserSession(userSession);
 72  
                     
 73  0
                     RequestParser requestParser = new RequestParser(request);
 74  0
                     String inputCommand = requestParser.getParameterValue("command");
 75  0
                     if (StringUtils.equals(inputCommand, "initiate")){
 76  0
                             requestParser.setParameterValue("userAction","initiate");
 77  
                     }
 78  0
                     String edlName = requestParser.getParameterValue("edlName");
 79  0
                     if (edlName == null) {
 80  0
                         edlName = requestParser.getParameterValue("docTypeName");//this is for 'WorkflowQuicklinks'
 81  
                     }
 82  0
                     EDLController edlController = null;
 83  
                     
 84  0
                     if (edlName == null) {
 85  0
                         documentId = requestParser.getParameterValue("docId");
 86  0
                         if (documentId == null) {
 87  0
                                 String docFormKey = requestParser.getParameterValue(KRADConstants.DOC_FORM_KEY);
 88  0
                                 if (docFormKey != null) {
 89  0
                                         Document document = (Document) GlobalVariables.getUserSession().retrieveObject(docFormKey);
 90  0
                                         Element documentState = EDLXmlUtils.getDocumentStateElement(document);
 91  0
                                         documentId = EDLXmlUtils.getChildElementTextValue(documentState, "docId");
 92  0
                                         requestParser.setAttribute(KRADConstants.DOC_FORM_KEY, docFormKey);
 93  
                                 }
 94  0
                                 if (documentId == null) {
 95  0
                                         throw new WorkflowRuntimeException("No edl name or document id detected");
 96  
                                 }
 97  
                         }
 98  0
                         requestParser.setAttribute("docId", documentId);
 99  0
                         edlController = EdlServiceLocator.getEDocLiteService().getEDLControllerUsingDocumentId(documentId);
 100  
                     } else {
 101  0
                         edlController = EdlServiceLocator.getEDocLiteService().getEDLControllerUsingEdlName(edlName);
 102  
                     }
 103  
 
 104  
                     //TODO Fix this in a better way (reworking the command structure maybe?)
 105  
                     //fix for KULRICE-4057 to make sure we don't destory docContent on empty command params
 106  0
                     if(inputCommand == null && requestParser.getParameterValue("docId") != null && !"POST".equals(request.getMethod())){
 107  
                             //make sure these are the only params on the request (paging passed undefined input command as well...
 108  0
                             if(!(request.getParameterMap().size() > 2)){//ensures ONLY documentId was passed
 109  0
                                     requestParser.setParameterValue("command", "displayDocSearchView");
 110  0
                                     LOG.info("command parameter was not passed with the request, and only document ID was. Defaulted command to 'displayDocSearchView' to ensure docContent remains.");
 111  
                             }
 112  
                     }
 113  
 
 114  0
                     EDLControllerChain controllerChain = new EDLControllerChain();
 115  0
                     controllerChain.addEdlController(edlController);
 116  
                         //TODO Do we not want to set the content type for the response?                   
 117  0
                     controllerChain.renderEDL(requestParser, response);
 118  
 
 119  0
                 } catch (Exception e) {
 120  0
                         LOG.error("Error processing EDL", e);
 121  0
                         outputError(request, response, e, documentId);
 122  
                 } finally {
 123  0
                     GlobalVariables.setUserSession(null);
 124  0
                 }
 125  0
         }
 126  
 
 127  
         private void outputError(HttpServletRequest request, HttpServletResponse response, Exception exception, String documentId) throws ServletException, IOException {
 128  0
                         IncidentReportUtils.populateRequestForIncidentReport(exception, "" + documentId, "eDoc Lite", request);
 129  0
                 RequestDispatcher rd = getServletContext().getRequestDispatcher(request.getServletPath() + "/../../kr/kualiExceptionIncidentReport.do");
 130  0
                 rd.forward(request, response);
 131  0
         }
 132  
 
 133  
 }