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