Coverage Report - org.kuali.rice.kew.edl.EDLServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
EDLServlet
0%
0/46
0%
0/20
5.333
 
 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.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  
  * Takes edl web requests.
 40  
  * 
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  *
 43  
  */
 44  0
 public class EDLServlet extends HttpServlet {
 45  
 
 46  
         private static final long serialVersionUID = -6344765194278430690L;
 47  
 
 48  0
         private static final Logger LOG = Logger.getLogger(EDLServlet.class);
 49  
 
 50  
         public void init() throws ServletException {
 51  
                 try {
 52  0
                         KEWServiceLocator.getEDocLiteService().initEDLGlobalConfig();
 53  0
                 } catch (Exception e) {
 54  0
                         LOG.error("Error initializing EDL", e);
 55  0
                 }
 56  
 
 57  0
         }
 58  
 
 59  
         protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 60  0
                 String documentId = null;
 61  
                 try {
 62  0
                     RequestParser requestParser = new RequestParser(request);
 63  0
                     String inputCommand = requestParser.getParameterValue("command");
 64  0
                     if (StringUtils.equals(inputCommand, "initiate")){
 65  0
                             requestParser.setParameterValue("userAction","initiate");
 66  
                     }
 67  0
                     String edlName = requestParser.getParameterValue("edlName");
 68  0
                     if (edlName == null) {
 69  0
                         edlName = requestParser.getParameterValue("docTypeName");//this is for 'WorkflowQuicklinks'
 70  
                     }
 71  0
                     EDLController edlController = null;
 72  
                     
 73  0
                     if (edlName == null) {
 74  0
                         documentId = requestParser.getParameterValue("docId");
 75  0
                         if (documentId == null) {
 76  0
                                 String docFormKey = requestParser.getParameterValue(KNSConstants.DOC_FORM_KEY);
 77  0
                                 if (docFormKey != null) {
 78  0
                                         Document document = (Document) UserSession.getAuthenticatedUser().retrieveObject(docFormKey);
 79  0
                                         Element documentState = EDLXmlUtils.getDocumentStateElement(document);
 80  0
                                         documentId = EDLXmlUtils.getChildElementTextValue(documentState, "docId");
 81  0
                                         requestParser.setAttribute(KNSConstants.DOC_FORM_KEY, docFormKey);
 82  
                                 }
 83  0
                                 if (documentId == null) {
 84  0
                                         throw new WorkflowRuntimeException("No edl name or document id detected");
 85  
                                 }
 86  
                         }
 87  0
                         requestParser.setAttribute("docId", documentId);
 88  0
                         edlController = KEWServiceLocator.getEDocLiteService().getEDLController(new Long(documentId));
 89  
                     } else {
 90  0
                         edlController = KEWServiceLocator.getEDocLiteService().getEDLController(edlName);
 91  
                     }
 92  
 
 93  
                     //TODO Fix this in a better way (reworking the command structure maybe?)
 94  
                     //fix for KULRICE-4057 to make sure we don't destory docContent on empty command params
 95  0
                     if(inputCommand == null && requestParser.getParameterValue("docId") != null && !"POST".equals(request.getMethod())){
 96  
                             //make sure these are the only params on the request (paging passed undefined input command as well...
 97  0
                             if(!(request.getParameterMap().size() > 2)){//ensures ONLY documentId was passed
 98  0
                                     requestParser.setParameterValue("command", "displayDocSearchView");
 99  0
                                     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  0
                     EDLControllerChain controllerChain = new EDLControllerChain();
 104  0
                     controllerChain.addEdlController(edlController);
 105  
                         //TODO Do we not want to set the content type for the response?                   
 106  0
                     controllerChain.renderEDL(requestParser, response);
 107  
 
 108  0
                 } catch (Exception e) {
 109  0
                         LOG.error("Error processing EDL", e);
 110  0
                         outputError(request, response, e, documentId);
 111  0
                 }
 112  0
         }
 113  
 
 114  
         private void outputError(HttpServletRequest request, HttpServletResponse response, Exception exception, String documentId) throws ServletException, IOException {
 115  0
                         IncidentReportUtils.populateRequestForIncidentReport(exception, ""+documentId, "eDoc Lite", request);
 116  0
                 RequestDispatcher rd = getServletContext().getRequestDispatcher(request.getServletPath() + "/../../kr/kualiExceptionIncidentReport.do");
 117  0
                 rd.forward(request, response);
 118  0
         }
 119  
 
 120  
 }