001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.module.cab.document.web.struts;
017
018 import javax.servlet.http.HttpServletRequest;
019 import javax.servlet.http.HttpServletResponse;
020
021 import org.apache.ojb.broker.OptimisticLockException;
022 import org.apache.struts.action.ActionForm;
023 import org.apache.struts.action.ActionForward;
024 import org.apache.struts.action.ActionMapping;
025 import org.kuali.kfs.module.cab.CabKeyConstants;
026 import org.kuali.kfs.sys.KFSConstants;
027 import org.kuali.kfs.sys.context.SpringContext;
028 import org.kuali.rice.core.util.RiceConstants;
029 import org.kuali.rice.kew.dto.RouteHeaderDTO;
030 import org.kuali.rice.kew.exception.WorkflowException;
031 import org.kuali.rice.kns.util.GlobalVariables;
032 import org.kuali.rice.kns.web.struts.action.KualiAction;
033 import org.kuali.rice.kns.workflow.service.KualiWorkflowInfo;
034 import org.springmodules.orm.ojb.OjbOperationException;
035
036 public class CabActionBase extends KualiAction {
037 @Override
038 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
039 ActionForward returnForward = mapping.findForward(RiceConstants.MAPPING_BASIC);
040
041 // if found methodToCall, pass control to that method
042 try {
043 returnForward = super.execute(mapping, form, request, response);
044 }
045 catch (OjbOperationException e) {
046 // special handling for OptimisticLockExceptions
047 OjbOperationException ooe = (OjbOperationException) e;
048
049 Throwable cause = ooe.getCause();
050 if (cause instanceof OptimisticLockException) {
051 OptimisticLockException ole = (OptimisticLockException) cause;
052 GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, CabKeyConstants.DATA_EDIT_LOCK_ERROR);
053 }
054 else {
055 // if exceptions are from 'save'
056 throw e;
057 }
058 }
059 return returnForward;
060 }
061
062
063 /**
064 * This method will process the view document request by clicking on a specific document.
065 *
066 * @param mapping ActionMapping
067 * @param form ActionForm
068 * @param request HttpServletRequest
069 * @param response HttpServletResponse
070 * @return ActionForward
071 * @throws Exception
072 */
073 public ActionForward viewDoc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
074 String documentId = request.getParameter("documentNumber");
075 KualiWorkflowInfo kualiWorkflowInfo = SpringContext.getBean(KualiWorkflowInfo.class);
076 try {
077 RouteHeaderDTO routeHeader = kualiWorkflowInfo.getRouteHeader(Long.valueOf(documentId));
078 String docHandlerUrl = routeHeader.getDocumentUrl();
079 if (docHandlerUrl.indexOf("?") == -1) {
080 docHandlerUrl += "?";
081 }
082 else {
083 docHandlerUrl += "&";
084 }
085
086 docHandlerUrl += "docId=" + documentId + "&" + "command=displayDocSearchView";
087 return new ActionForward(docHandlerUrl, true);
088 }
089 catch (WorkflowException e) {
090 throw new RuntimeException("Caught WorkflowException trying to get document handler URL from Workflow", e);
091 }
092 }
093 }