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-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.routing.web;
 17  
 
 18  
 import javax.servlet.http.HttpServletRequest;
 19  
 import javax.servlet.http.HttpServletResponse;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.apache.struts.action.ActionForm;
 23  
 import org.apache.struts.action.ActionForward;
 24  
 import org.apache.struts.action.ActionMapping;
 25  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 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.routeheader.DocumentRouteHeaderValue;
 30  
 import org.kuali.rice.kew.routeheader.service.RouteHeaderService;
 31  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 32  
 import org.kuali.rice.kew.api.KewApiConstants;
 33  
 import org.kuali.rice.kew.web.KewKualiAction;
 34  
 import org.kuali.rice.krad.UserSession;
 35  
 import org.kuali.rice.krad.util.GlobalVariables;
 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  
     @Override
 47  
         public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 48  0
         DocHandlerForm docHandlerForm = (DocHandlerForm) form;
 49  
 
 50  0
         String docHandler = null;
 51  
 
 52  0
         if (request.getParameter(KewApiConstants.DOCUMENT_ID_PARAMETER) != null) {
 53  0
             RouteHeaderService rhSrv = (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV);
 54  0
             DocumentRouteHeaderValue routeHeader = rhSrv.getRouteHeader(docHandlerForm.getDocId());
 55  
 
 56  0
             if (!KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(GlobalVariables.getUserSession().getPrincipalId(), routeHeader, new SecuritySession(GlobalVariables.getUserSession().getPrincipalId()))) {
 57  0
                     return mapping.findForward("NotAuthorized");
 58  
             }
 59  0
             docHandler = routeHeader.getDocumentType().getDocHandlerUrl();
 60  0
             if (StringUtils.isBlank(docHandler)) {
 61  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() + ")");
 62  
             }
 63  0
             if (!docHandler.contains("?")) {
 64  0
                 docHandler += "?";
 65  
             } else {
 66  0
                 docHandler += "&";
 67  
             }
 68  0
             docHandler += KewApiConstants.DOCUMENT_ID_PARAMETER + "=" + docHandlerForm.getDocId();
 69  0
         } else if (request.getParameter(KewApiConstants.DOCTYPE_PARAMETER) != null) {
 70  0
             DocumentTypeService documentTypeService = (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
 71  0
             DocumentType documentType = documentTypeService.findByName(docHandlerForm.getDocTypeName());
 72  0
             docHandler = documentType.getDocHandlerUrl();
 73  0
             if (StringUtils.isBlank(docHandler)) {
 74  0
                 throw new WorkflowRuntimeException("Cannot find document handler url for document type '" + documentType.getName() + "'");
 75  
             }
 76  0
             if (!docHandler.contains("?")) {
 77  0
                 docHandler += "?";
 78  
             } else {
 79  0
                 docHandler += "&";
 80  
             }
 81  0
             docHandler += KewApiConstants.DOCTYPE_PARAMETER + "=" + docHandlerForm.getDocTypeName();
 82  0
         } else {
 83  
 //TODO what should happen here if parms are missing; no proper ActionForward from here
 84  0
             throw new RuntimeException ("Cannot determine document handler");
 85  
         }
 86  
 
 87  0
         docHandler += "&" + KewApiConstants.COMMAND_PARAMETER + "=" + docHandlerForm.getCommand();
 88  0
         if (getUserSession(request).isBackdoorInUse()) {
 89  0
             docHandler += "&" + KewApiConstants.BACKDOOR_ID_PARAMETER + "=" + getUserSession(request).getPrincipalName();
 90  
         }
 91  0
         return new ActionForward(docHandler, true);
 92  
     }
 93  
 
 94  
     public static UserSession getUserSession(HttpServletRequest request) {
 95  0
         return GlobalVariables.getUserSession();
 96  
     }
 97  
 }