Coverage Report - org.kuali.rice.kew.routing.web.ClientAppDocHandlerRedirectAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ClientAppDocHandlerRedirectAction
0%
0/32
0%
0/16
7
 
 1  
 /*
 2  
  * Copyright 2005-2008 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.routing.web;
 18  
 
 19  
 import javax.servlet.http.HttpServletRequest;
 20  
 import javax.servlet.http.HttpServletResponse;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.apache.struts.action.ActionForm;
 24  
 import org.apache.struts.action.ActionForward;
 25  
 import org.apache.struts.action.ActionMapping;
 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.exception.WorkflowRuntimeException;
 30  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 31  
 import org.kuali.rice.kew.routeheader.service.RouteHeaderService;
 32  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 33  
 import org.kuali.rice.kew.util.KEWConstants;
 34  
 import org.kuali.rice.kew.web.KewKualiAction;
 35  
 import org.kuali.rice.kns.UserSession;
 36  
 import org.kuali.rice.kns.util.GlobalVariables;
 37  
 
 38  
 
 39  
 /**
 40  
  * A Struts Action for redirecting from the KEW web application to the appropriate
 41  
  * Doc Handler for a document.
 42  
  *
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 44  
  */
 45  0
 public class ClientAppDocHandlerRedirectAction extends KewKualiAction {
 46  
 
 47  
     @Override
 48  
         public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 49  0
         DocHandlerForm docHandlerForm = (DocHandlerForm) form;
 50  
 
 51  0
         String docHandler = null;
 52  
 
 53  0
         if (request.getParameter(KEWConstants.DOCUMENT_ID_PARAMETER) != null) {
 54  0
             RouteHeaderService rhSrv = (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV);
 55  0
             DocumentRouteHeaderValue routeHeader = rhSrv.getRouteHeader(docHandlerForm.getDocId());
 56  
 
 57  0
             if (!KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(GlobalVariables.getUserSession(), routeHeader, new SecuritySession(GlobalVariables.getUserSession()))) {
 58  0
                     return mapping.findForward("NotAuthorized");
 59  
             }
 60  0
             docHandler = routeHeader.getDocumentType().getDocHandlerUrl();
 61  0
             if (StringUtils.isBlank(docHandler)) {
 62  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() + ")");
 63  
             }
 64  0
             if (!docHandler.contains("?")) {
 65  0
                 docHandler += "?";
 66  
             } else {
 67  0
                 docHandler += "&";
 68  
             }
 69  0
             docHandler += KEWConstants.DOCUMENT_ID_PARAMETER + "=" + docHandlerForm.getDocId();
 70  0
         } else if (request.getParameter(KEWConstants.DOCTYPE_PARAMETER) != null) {
 71  0
             DocumentTypeService documentTypeService = (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
 72  0
             DocumentType documentType = documentTypeService.findByName(docHandlerForm.getDocTypeName());
 73  0
             docHandler = documentType.getDocHandlerUrl();
 74  0
             if (StringUtils.isBlank(docHandler)) {
 75  0
                 throw new WorkflowRuntimeException("Cannot find document handler url for document type '" + documentType.getName() + "'");
 76  
             }
 77  0
             if (!docHandler.contains("?")) {
 78  0
                 docHandler += "?";
 79  
             } else {
 80  0
                 docHandler += "&";
 81  
             }
 82  0
             docHandler += KEWConstants.DOCTYPE_PARAMETER + "=" + docHandlerForm.getDocTypeName();
 83  0
         } else {
 84  
 //TODO what should happen here if parms are missing; no proper ActionForward from here
 85  0
             throw new RuntimeException ("Cannot determine document handler");
 86  
         }
 87  
 
 88  0
         docHandler += "&" + KEWConstants.COMMAND_PARAMETER + "=" + docHandlerForm.getCommand();
 89  0
         if (getUserSession(request).isBackdoorInUse()) {
 90  0
             docHandler += "&" + KEWConstants.BACKDOOR_ID_PARAMETER + "=" + getUserSession(request).getPrincipalName();
 91  
         }
 92  0
         return new ActionForward(docHandler, true);
 93  
     }
 94  
 
 95  
     public static UserSession getUserSession(HttpServletRequest request) {
 96  0
         return GlobalVariables.getUserSession();
 97  
     }
 98  
 }