|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
   package org.kuali.rice.kns.web.struts.action;  | 
  |  14 |     | 
     | 
  |  15 |     | 
   import org.apache.commons.lang.StringUtils;  | 
  |  16 |     | 
   import org.apache.log4j.Logger;  | 
  |  17 |     | 
   import org.apache.log4j.MDC;  | 
  |  18 |     | 
   import org.apache.ojb.broker.OptimisticLockException;  | 
  |  19 |     | 
   import org.apache.struts.Globals;  | 
  |  20 |     | 
   import org.apache.struts.action.*;  | 
  |  21 |     | 
   import org.apache.struts.config.FormBeanConfig;  | 
  |  22 |     | 
   import org.apache.struts.config.ForwardConfig;  | 
  |  23 |     | 
   import org.apache.struts.util.RequestUtils;  | 
  |  24 |     | 
   import org.kuali.rice.core.util.RiceConstants;  | 
  |  25 |     | 
   import org.kuali.rice.core.util.RiceKeyConstants;  | 
  |  26 |     | 
   import org.kuali.rice.kns.UserSession;  | 
  |  27 |     | 
   import org.kuali.rice.kns.document.Document;  | 
  |  28 |     | 
   import org.kuali.rice.kns.exception.FileUploadLimitExceededException;  | 
  |  29 |     | 
   import org.kuali.rice.kns.exception.ValidationException;  | 
  |  30 |     | 
   import org.kuali.rice.kns.service.KNSServiceLocator;  | 
  |  31 |     | 
   import org.kuali.rice.kns.service.KNSServiceLocatorInternal;  | 
  |  32 |     | 
   import org.kuali.rice.kns.service.KNSServiceLocatorWeb;  | 
  |  33 |     | 
   import org.kuali.rice.kns.service.SessionDocumentService;  | 
  |  34 |     | 
   import org.kuali.rice.kns.util.*;  | 
  |  35 |     | 
   import org.kuali.rice.kns.web.EditablePropertiesHistoryHolder;  | 
  |  36 |     | 
   import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;  | 
  |  37 |     | 
   import org.kuali.rice.kns.web.struts.form.KualiForm;  | 
  |  38 |     | 
   import org.kuali.rice.kns.web.struts.pojo.PojoForm;  | 
  |  39 |     | 
   import org.springframework.transaction.PlatformTransactionManager;  | 
  |  40 |     | 
   import org.springframework.transaction.TransactionStatus;  | 
  |  41 |     | 
   import org.springframework.transaction.support.TransactionCallback;  | 
  |  42 |     | 
   import org.springframework.transaction.support.TransactionTemplate;  | 
  |  43 |     | 
   import org.springmodules.orm.ojb.OjbOperationException;  | 
  |  44 |     | 
     | 
  |  45 |     | 
   import javax.servlet.ServletException;  | 
  |  46 |     | 
   import javax.servlet.http.HttpServletRequest;  | 
  |  47 |     | 
   import javax.servlet.http.HttpServletResponse;  | 
  |  48 |     | 
   import javax.servlet.http.HttpSession;  | 
  |  49 |     | 
   import java.io.IOException;  | 
  |  50 |     | 
     | 
  |  51 |     | 
     | 
  |  52 |     | 
     | 
  |  53 |     | 
     | 
  |  54 |     | 
     | 
  |  55 |     | 
     | 
  |  56 |    0 |    public class KualiRequestProcessor extends RequestProcessor { | 
  |  57 |     | 
             | 
  |  58 |     | 
           private static final String MDC_DOC_ID = "docId";  | 
  |  59 |     | 
           private static final String PREVIOUS_REQUEST_EDITABLE_PROPERTIES_GUID_PARAMETER_NAME = "actionEditablePropertiesGuid";  | 
  |  60 |     | 
     | 
  |  61 |    0 |            private static Logger LOG = Logger.getLogger(KualiRequestProcessor.class);  | 
  |  62 |     | 
     | 
  |  63 |     | 
           private SessionDocumentService sessionDocumentService;  | 
  |  64 |     | 
           private PlatformTransactionManager transactionManager;  | 
  |  65 |     | 
             | 
  |  66 |     | 
           @Override  | 
  |  67 |     | 
           public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { | 
  |  68 |    0 |                    if ( LOG.isInfoEnabled() ) { | 
  |  69 |    0 |                            LOG.info(new StringBuffer("Started processing request: '").append(request.getRequestURI()).append("' w/ query string: '").append(request.getQueryString()).append("'")); | 
  |  70 |     | 
                   }  | 
  |  71 |     | 
     | 
  |  72 |     | 
                   try {  | 
  |  73 |    0 |                            strutsProcess(request, response);  | 
  |  74 |    0 |                    } catch (FileUploadLimitExceededException e) { | 
  |  75 |    0 |                            ActionForward actionForward = processException(request, response, e, e.getActionForm(), e.getActionMapping());  | 
  |  76 |    0 |                            processForwardConfig(request, response, actionForward);  | 
  |  77 |     | 
                   } finally { | 
  |  78 |    0 |                            GlobalVariables.setKualiForm(null);  | 
  |  79 |    0 |                    }  | 
  |  80 |     | 
                             | 
  |  81 |     | 
                   try { | 
  |  82 |    0 |                            ActionForm form = WebUtils.getKualiForm(request);  | 
  |  83 |     | 
                             | 
  |  84 |    0 |                            if (form != null && form instanceof KualiDocumentFormBase) { | 
  |  85 |    0 |                                    String docId = ((KualiDocumentFormBase) form).getDocId();  | 
  |  86 |    0 |                                    if (docId != null) { MDC.put(MDC_DOC_ID, docId); } | 
  |  87 |     | 
                           }  | 
  |  88 |     | 
     | 
  |  89 |    0 |                            String refreshCaller = request.getParameter(KNSConstants.REFRESH_CALLER);  | 
  |  90 |    0 |                            if (form!=null && KualiDocumentFormBase.class.isAssignableFrom(form.getClass())   | 
  |  91 |     | 
                                           && !KNSConstants.QUESTION_REFRESH.equalsIgnoreCase(refreshCaller)) { | 
  |  92 |    0 |                                    KualiDocumentFormBase docForm = (KualiDocumentFormBase) form;  | 
  |  93 |    0 |                                    Document document = docForm.getDocument();  | 
  |  94 |    0 |                                    String docFormKey = docForm.getFormKey();  | 
  |  95 |     | 
     | 
  |  96 |    0 |                                    UserSession userSession = (UserSession) request.getSession().getAttribute(KNSConstants.USER_SESSION_KEY);  | 
  |  97 |     | 
     | 
  |  98 |    0 |                                    if (WebUtils.isDocumentSession(document, docForm)) { | 
  |  99 |    0 |                                            getSessionDocumentService().setDocumentForm(docForm, userSession, request.getRemoteAddr());  | 
  |  100 |     | 
                                   }  | 
  |  101 |     | 
     | 
  |  102 |    0 |                                    Boolean exitingDocument = (Boolean) request.getAttribute(KNSConstants.EXITING_DOCUMENT);  | 
  |  103 |     | 
     | 
  |  104 |    0 |                                    if (exitingDocument != null && exitingDocument.booleanValue()) { | 
  |  105 |     | 
                                             | 
  |  106 |     | 
                                             | 
  |  107 |    0 |                                            getSessionDocumentService().purgeDocumentForm(docForm.getDocument().getDocumentNumber(), docFormKey, userSession, request.getRemoteAddr());  | 
  |  108 |     | 
                                   }  | 
  |  109 |     | 
                           }  | 
  |  110 |     | 
     | 
  |  111 |    0 |                            if ( LOG.isInfoEnabled() ) { | 
  |  112 |    0 |                                    LOG.info(new StringBuffer("Finished processing request: '").append(request.getRequestURI()).append("' w/ query string: '").append(request.getQueryString()).append("'")); | 
  |  113 |     | 
                           }  | 
  |  114 |     | 
     | 
  |  115 |     | 
                   } finally { | 
  |  116 |     | 
                             | 
  |  117 |    0 |                            MDC.remove(MDC_DOC_ID);  | 
  |  118 |    0 |                    }  | 
  |  119 |     | 
     | 
  |  120 |    0 |            }  | 
  |  121 |     | 
             | 
  |  122 |     | 
           @Override  | 
  |  123 |     | 
           protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) { | 
  |  124 |    0 |            final UserSession session = WebUtils.getUserSessionFromRequest(request);  | 
  |  125 |     | 
             | 
  |  126 |    0 |            if (session == null) { | 
  |  127 |    0 |                    throw new IllegalStateException("the user session has not been established"); | 
  |  128 |     | 
           }  | 
  |  129 |    0 |                GlobalVariables.setUserSession(session);  | 
  |  130 |    0 |                GlobalVariables.clear();  | 
  |  131 |    0 |                    return true;  | 
  |  132 |     | 
           }  | 
  |  133 |     | 
             | 
  |  134 |     | 
             | 
  |  135 |     | 
     | 
  |  136 |     | 
     | 
  |  137 |     | 
     | 
  |  138 |     | 
     | 
  |  139 |     | 
     | 
  |  140 |     | 
     | 
  |  141 |     | 
     | 
  |  142 |     | 
     | 
  |  143 |     | 
     | 
  |  144 |     | 
     | 
  |  145 |     | 
       public void strutsProcess(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { | 
  |  146 |     | 
     | 
  |  147 |     | 
             | 
  |  148 |    0 |            request = processMultipart(request);  | 
  |  149 |     | 
     | 
  |  150 |     | 
             | 
  |  151 |    0 |            String path = processPath(request, response);  | 
  |  152 |    0 |            if (path == null) { | 
  |  153 |    0 |                return;  | 
  |  154 |     | 
           }  | 
  |  155 |     | 
             | 
  |  156 |    0 |            if (log.isDebugEnabled()) { | 
  |  157 |    0 |                log.debug("Processing a '" + request.getMethod() + | 
  |  158 |     | 
                         "' for path '" + path + "'");  | 
  |  159 |     | 
           }  | 
  |  160 |     | 
     | 
  |  161 |     | 
             | 
  |  162 |    0 |            processLocale(request, response);  | 
  |  163 |     | 
     | 
  |  164 |     | 
             | 
  |  165 |    0 |            processContent(request, response);  | 
  |  166 |    0 |            processNoCache(request, response);  | 
  |  167 |     | 
     | 
  |  168 |     | 
             | 
  |  169 |    0 |            if (!processPreprocess(request, response)) { | 
  |  170 |    0 |                return;  | 
  |  171 |     | 
           }  | 
  |  172 |     | 
             | 
  |  173 |    0 |            this.processCachedMessages(request, response);  | 
  |  174 |     | 
     | 
  |  175 |     | 
             | 
  |  176 |    0 |            ActionMapping mapping = processMapping(request, response, path);  | 
  |  177 |    0 |            if (mapping == null) { | 
  |  178 |    0 |                return;  | 
  |  179 |     | 
           }  | 
  |  180 |     | 
     | 
  |  181 |     | 
             | 
  |  182 |    0 |            if (!processRoles(request, response, mapping)) { | 
  |  183 |    0 |                return;  | 
  |  184 |     | 
           }  | 
  |  185 |     | 
     | 
  |  186 |    0 |            processFormActionAndForward(request, response, mapping);  | 
  |  187 |     | 
     | 
  |  188 |    0 |        }  | 
  |  189 |     | 
         | 
  |  190 |     | 
       public void processFormActionAndForward(final HttpServletRequest request, final HttpServletResponse response, final ActionMapping mapping) throws ServletException, IOException { | 
  |  191 |    0 |                TransactionTemplate template = new TransactionTemplate(getTransactionManager());  | 
  |  192 |     | 
               try { | 
  |  193 |    0 |                            template.execute(new TransactionCallback() { | 
  |  194 |     | 
                                   @Override  | 
  |  195 |     | 
                                   public Object doInTransaction(TransactionStatus status) { | 
  |  196 |     | 
                                           try { | 
  |  197 |     | 
                                                     | 
  |  198 |    0 |                                            ActionForm form = processActionForm(request, response, mapping);  | 
  |  199 |    0 |                                            processPopulate(request, response, form, mapping);  | 
  |  200 |     | 
                                             | 
  |  201 |     | 
                                             | 
  |  202 |     | 
                                           try { | 
  |  203 |    0 |                                                if (!processValidate(request, response, form, mapping)) { | 
  |  204 |    0 |                                                    return null;  | 
  |  205 |     | 
                                               }  | 
  |  206 |    0 |                                            } catch (InvalidCancelException e) { | 
  |  207 |    0 |                                                ActionForward forward = processException(request, response, e, form, mapping);  | 
  |  208 |    0 |                                                processForwardConfig(request, response, forward);  | 
  |  209 |    0 |                                                return null;  | 
  |  210 |    0 |                                            } catch (IOException e) { | 
  |  211 |    0 |                                                throw e;  | 
  |  212 |    0 |                                            } catch (ServletException e) { | 
  |  213 |    0 |                                                throw e;  | 
  |  214 |    0 |                                            }  | 
  |  215 |     | 
                                                 | 
  |  216 |     | 
                                             | 
  |  217 |    0 |                                            if (!processForward(request, response, mapping)) { | 
  |  218 |    0 |                                                return null;  | 
  |  219 |     | 
                                           }  | 
  |  220 |     | 
                                             | 
  |  221 |    0 |                                            if (!processInclude(request, response, mapping)) { | 
  |  222 |    0 |                                                return null;  | 
  |  223 |     | 
                                           }  | 
  |  224 |     | 
     | 
  |  225 |     | 
                                             | 
  |  226 |    0 |                                            Action action = processActionCreate(request, response, mapping);  | 
  |  227 |    0 |                                            if (action == null) { | 
  |  228 |    0 |                                                return null;  | 
  |  229 |     | 
                                           }  | 
  |  230 |     | 
                                                     | 
  |  231 |     | 
                                                 | 
  |  232 |    0 |                                            ActionForward forward = processActionPerform(request, response, action, form, mapping);  | 
  |  233 |     | 
                                     | 
  |  234 |     | 
                                             | 
  |  235 |    0 |                                            processForwardConfig(request, response, forward);  | 
  |  236 |    0 |                                            } catch (Exception e) { | 
  |  237 |     | 
                                                     | 
  |  238 |     | 
                                                     | 
  |  239 |     | 
                                                     | 
  |  240 |     | 
                                                     | 
  |  241 |     | 
                                                     | 
  |  242 |     | 
                                                     | 
  |  243 |     | 
                                                     | 
  |  244 |     | 
                                                     | 
  |  245 |    0 |                                                    throw new WrappedRuntimeException(e);  | 
  |  246 |    0 |                                            }  | 
  |  247 |    0 |                                            return null;  | 
  |  248 |     | 
                                   }  | 
  |  249 |     | 
                           });  | 
  |  250 |    0 |                    } catch (WrappedRuntimeException wre) { | 
  |  251 |    0 |                            throw new RuntimeException(wre.getCause());  | 
  |  252 |    0 |                    }  | 
  |  253 |    0 |        }  | 
  |  254 |     | 
     | 
  |  255 |     | 
     | 
  |  256 |     | 
             | 
  |  257 |     | 
     | 
  |  258 |     | 
     | 
  |  259 |     | 
     | 
  |  260 |     | 
     | 
  |  261 |     | 
     | 
  |  262 |     | 
     | 
  |  263 |     | 
           private String getDocumentNumber(HttpServletRequest request) { | 
  |  264 |    0 |                    String documentNumber = request.getParameter(KNSConstants.DOCUMENT_DOCUMENT_NUMBER);  | 
  |  265 |     | 
     | 
  |  266 |     | 
                     | 
  |  267 |    0 |                    if (documentNumber == null) { | 
  |  268 |    0 |                            documentNumber = request.getParameter(KNSConstants.DOC_NUM);  | 
  |  269 |     | 
                   }  | 
  |  270 |     | 
                     | 
  |  271 |    0 |                    if (documentNumber == null) { | 
  |  272 |    0 |                            documentNumber = request.getParameter("routeHeaderId"); | 
  |  273 |     | 
                   }  | 
  |  274 |     | 
                     | 
  |  275 |    0 |                    return documentNumber;  | 
  |  276 |     | 
           }  | 
  |  277 |     | 
     | 
  |  278 |     | 
             | 
  |  279 |     | 
     | 
  |  280 |     | 
     | 
  |  281 |     | 
     | 
  |  282 |     | 
           @Override  | 
  |  283 |     | 
           protected void processPopulate(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping) throws ServletException { | 
  |  284 |    0 |                    if (form instanceof KualiForm) { | 
  |  285 |     | 
                             | 
  |  286 |     | 
                             | 
  |  287 |     | 
                             | 
  |  288 |     | 
                             | 
  |  289 |     | 
                             | 
  |  290 |    0 |                            GlobalVariables.setKualiForm((KualiForm) form);  | 
  |  291 |     | 
                   }  | 
  |  292 |     | 
     | 
  |  293 |     | 
                     | 
  |  294 |    0 |                    if (!(form instanceof PojoForm)) { | 
  |  295 |    0 |                            super.processPopulate(request, response, form, mapping);  | 
  |  296 |    0 |                            return;  | 
  |  297 |     | 
                   }  | 
  |  298 |     | 
                     | 
  |  299 |    0 |                    final String previousRequestGuid = request.getParameter(KualiRequestProcessor.PREVIOUS_REQUEST_EDITABLE_PROPERTIES_GUID_PARAMETER_NAME);  | 
  |  300 |     | 
     | 
  |  301 |    0 |                    ((PojoForm)form).clearEditablePropertyInformation();  | 
  |  302 |    0 |                    ((PojoForm)form).registerStrutsActionMappingScope(mapping.getScope());  | 
  |  303 |     | 
                     | 
  |  304 |    0 |                    String multipart = mapping.getMultipartClass();  | 
  |  305 |    0 |                    if (multipart != null) { | 
  |  306 |    0 |                            request.setAttribute(Globals.MULTIPART_KEY, multipart);  | 
  |  307 |     | 
                   }  | 
  |  308 |     | 
     | 
  |  309 |    0 |                    form.setServlet(this.servlet);  | 
  |  310 |    0 |                    form.reset(mapping, request);  | 
  |  311 |     | 
     | 
  |  312 |    0 |                    ((PojoForm)form).setPopulateEditablePropertiesGuid(previousRequestGuid);  | 
  |  313 |     | 
                     | 
  |  314 |    0 |                    ((PojoForm) form).populate(request);  | 
  |  315 |    0 |                    request.setAttribute("UnconvertedValues", ((PojoForm) form).getUnconvertedValues().keySet()); | 
  |  316 |    0 |                    request.setAttribute("UnconvertedHash", ((PojoForm) form).getUnconvertedValues()); | 
  |  317 |    0 |            }  | 
  |  318 |     | 
     | 
  |  319 |     | 
             | 
  |  320 |     | 
     | 
  |  321 |     | 
     | 
  |  322 |     | 
     | 
  |  323 |     | 
           @Override  | 
  |  324 |     | 
           protected boolean processValidate(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping) throws IOException, ServletException, InvalidCancelException { | 
  |  325 |     | 
     | 
  |  326 |     | 
                     | 
  |  327 |    0 |                    if (GlobalVariables.getMessageMap().hasNoErrors()) { | 
  |  328 |    0 |                            if (form == null) { | 
  |  329 |    0 |                                    return (true);  | 
  |  330 |     | 
                           }  | 
  |  331 |     | 
                             | 
  |  332 |    0 |                            if (request.getAttribute(Globals.CANCEL_KEY) != null) { | 
  |  333 |    0 |                                    if (LOG.isDebugEnabled()) { | 
  |  334 |    0 |                                            LOG.debug(" Cancelled transaction, skipping validation"); | 
  |  335 |     | 
                                   }  | 
  |  336 |    0 |                                    return (true);  | 
  |  337 |     | 
                           }  | 
  |  338 |     | 
     | 
  |  339 |     | 
                             | 
  |  340 |    0 |                            if (!mapping.getValidate()) { | 
  |  341 |    0 |                                    return (true);  | 
  |  342 |     | 
                           }  | 
  |  343 |     | 
     | 
  |  344 |     | 
                             | 
  |  345 |    0 |                            super.processValidate(request, response, form, mapping);  | 
  |  346 |     | 
                   }  | 
  |  347 |     | 
     | 
  |  348 |    0 |                    publishMessages(request);  | 
  |  349 |    0 |                    if (!GlobalVariables.getMessageMap().hasNoErrors()) { | 
  |  350 |     | 
                             | 
  |  351 |    0 |                            if (form.getMultipartRequestHandler() != null) { | 
  |  352 |    0 |                                    if (LOG.isDebugEnabled()) { | 
  |  353 |    0 |                                            LOG.debug("  Rolling back multipart request"); | 
  |  354 |     | 
                                   }  | 
  |  355 |    0 |                                    form.getMultipartRequestHandler().rollback();  | 
  |  356 |     | 
                           }  | 
  |  357 |     | 
     | 
  |  358 |     | 
                             | 
  |  359 |    0 |                            if (form instanceof PojoForm) { | 
  |  360 |    0 |                                    ((PojoForm) form).processValidationFail();  | 
  |  361 |     | 
                           }  | 
  |  362 |     | 
     | 
  |  363 |     | 
                             | 
  |  364 |    0 |                            String input = mapping.getInput();  | 
  |  365 |    0 |                            if (input == null) { | 
  |  366 |    0 |                                    if (LOG.isDebugEnabled()) { | 
  |  367 |    0 |                                            LOG.debug("  Validation failed but no input form available"); | 
  |  368 |     | 
                                   }  | 
  |  369 |    0 |                                    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getInternal().getMessage("noInput", mapping.getPath())); | 
  |  370 |    0 |                                    return (false);  | 
  |  371 |     | 
                           }  | 
  |  372 |     | 
     | 
  |  373 |    0 |                            if (moduleConfig.getControllerConfig().getInputForward()) { | 
  |  374 |    0 |                                    ForwardConfig forward = mapping.findForward(input);  | 
  |  375 |    0 |                                    processForwardConfig(request, response, forward);  | 
  |  376 |    0 |                            } else { | 
  |  377 |    0 |                                    internalModuleRelativeForward(input, request, response);  | 
  |  378 |     | 
                           }  | 
  |  379 |     | 
     | 
  |  380 |    0 |                            return (false);  | 
  |  381 |     | 
                   }  | 
  |  382 |    0 |                    return true;  | 
  |  383 |     | 
           }  | 
  |  384 |     | 
     | 
  |  385 |     | 
             | 
  |  386 |     | 
     | 
  |  387 |     | 
     | 
  |  388 |     | 
     | 
  |  389 |     | 
           @Override  | 
  |  390 |     | 
           protected ActionForm processActionForm(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) { | 
  |  391 |     | 
                     | 
  |  392 |    0 |                    String documentNumber = getDocumentNumber(request);  | 
  |  393 |    0 |                    if (documentNumber != null) { MDC.put(MDC_DOC_ID, documentNumber); } | 
  |  394 |     | 
                     | 
  |  395 |    0 |                    UserSession userSession = (UserSession) request.getSession().getAttribute(KNSConstants.USER_SESSION_KEY);  | 
  |  396 |     | 
     | 
  |  397 |    0 |                    String docFormKey = request.getParameter(KNSConstants.DOC_FORM_KEY);  | 
  |  398 |    0 |                    String methodToCall = request.getParameter(KNSConstants.DISPATCH_REQUEST_PARAMETER);  | 
  |  399 |    0 |                    String refreshCaller = request.getParameter(KNSConstants.REFRESH_CALLER);  | 
  |  400 |     | 
     | 
  |  401 |    0 |                    String documentWebScope = request.getParameter(KNSConstants.DOCUMENT_WEB_SCOPE);  | 
  |  402 |     | 
     | 
  |  403 |    0 |                    if (mapping.getPath().startsWith(KNSConstants.REFRESH_MAPPING_PREFIX) || KNSConstants.RETURN_METHOD_TO_CALL.equalsIgnoreCase(methodToCall) ||  | 
  |  404 |     | 
                                   KNSConstants.QUESTION_REFRESH.equalsIgnoreCase(refreshCaller) || KNSConstants.TEXT_AREA_REFRESH.equalsIgnoreCase(refreshCaller) || KNSConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope)) { | 
  |  405 |    0 |                            ActionForm form = null;  | 
  |  406 |     | 
                             | 
  |  407 |    0 |                            GlobalVariables.getUserSession().removeObjectsByPrefix(KNSConstants.SEARCH_LIST_KEY_PREFIX);  | 
  |  408 |     | 
     | 
  |  409 |     | 
                             | 
  |  410 |     | 
                             | 
  |  411 |     | 
                             | 
  |  412 |    0 |                            if (userSession.retrieveObject(docFormKey) != null) { | 
  |  413 |    0 |                                    LOG.debug("getDecomentForm KualiDocumentFormBase from session"); | 
  |  414 |    0 |                                    form = (ActionForm) userSession.retrieveObject(docFormKey);  | 
  |  415 |     | 
                           } else { | 
  |  416 |    0 |                                    form = getSessionDocumentService().getDocumentForm(documentNumber, docFormKey, userSession, request.getRemoteAddr());  | 
  |  417 |     | 
                           }  | 
  |  418 |    0 |                            request.setAttribute(mapping.getAttribute(), form);  | 
  |  419 |    0 |                            if (!KNSConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope)) { | 
  |  420 |    0 |                                    userSession.removeObject(docFormKey);  | 
  |  421 |     | 
                           }  | 
  |  422 |     | 
                             | 
  |  423 |     | 
                             | 
  |  424 |     | 
                             | 
  |  425 |    0 |                            String contentType = request.getContentType();  | 
  |  426 |    0 |                            String method = request.getMethod();  | 
  |  427 |    0 |                            if (("POST".equalsIgnoreCase(method) && contentType != null && contentType.startsWith("multipart/form-data"))) { | 
  |  428 |     | 
                                     | 
  |  429 |     | 
                                     | 
  |  430 |    0 |                                    WebUtils.getMultipartParameters(request, null, form, mapping);  | 
  |  431 |     | 
                           }  | 
  |  432 |     | 
                             | 
  |  433 |    0 |                            if (form != null) { | 
  |  434 |    0 |                                    return form;  | 
  |  435 |     | 
                           }  | 
  |  436 |     | 
                   }  | 
  |  437 |     | 
     | 
  |  438 |     | 
                     | 
  |  439 |     | 
                     | 
  |  440 |     | 
                     | 
  |  441 |     | 
                     | 
  |  442 |     | 
                     | 
  |  443 |    0 |                    ActionForm form = super.processActionForm(request, response, mapping);  | 
  |  444 |     | 
     | 
  |  445 |     | 
                     | 
  |  446 |    0 |                    String contentType = request.getContentType();  | 
  |  447 |    0 |                    String method = request.getMethod();  | 
  |  448 |     | 
     | 
  |  449 |    0 |                    if ("GET".equalsIgnoreCase(method) && StringUtils.isNotBlank(methodToCall) && form instanceof PojoForm && | 
  |  450 |     | 
                                   ((PojoForm) form).getMethodToCallsToBypassSessionRetrievalForGETRequests().contains(methodToCall)) { | 
  |  451 |    0 |                            return createNewActionForm(mapping, request);  | 
  |  452 |     | 
                   }  | 
  |  453 |     | 
                     | 
  |  454 |     | 
                     | 
  |  455 |     | 
                     | 
  |  456 |     | 
                     | 
  |  457 |     | 
                     | 
  |  458 |     | 
                     | 
  |  459 |     | 
                     | 
  |  460 |     | 
                     | 
  |  461 |     | 
                     | 
  |  462 |     | 
                     | 
  |  463 |     | 
                     | 
  |  464 |    0 |                    if (("POST".equalsIgnoreCase(method) && contentType != null && contentType.startsWith("multipart/form-data"))) { | 
  |  465 |    0 |                            WebUtils.getMultipartParameters(request, null, form, mapping);  | 
  |  466 |    0 |                            docFormKey = request.getParameter(KNSConstants.DOC_FORM_KEY);  | 
  |  467 |    0 |                            documentWebScope = request.getParameter(KNSConstants.DOCUMENT_WEB_SCOPE);  | 
  |  468 |     | 
     | 
  |  469 |    0 |                            documentNumber = getDocumentNumber(request);  | 
  |  470 |     | 
     | 
  |  471 |    0 |                            if (KNSConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope) ||  | 
  |  472 |     | 
                                           (form instanceof KualiDocumentFormBase && WebUtils.isDocumentSession(((KualiDocumentFormBase) form).getDocument(), (KualiDocumentFormBase) form))) { | 
  |  473 |     | 
     | 
  |  474 |    0 |                                    Object userSessionObject = userSession.retrieveObject(docFormKey);  | 
  |  475 |    0 |                                    if ( userSessionObject != null &&  userSessionObject instanceof ActionForm ) { | 
  |  476 |    0 |                                            LOG.debug("getDocumentForm KualiDocumentFormBase from session"); | 
  |  477 |    0 |                                            form = (ActionForm) userSessionObject;  | 
  |  478 |     | 
                                   } else { | 
  |  479 |    0 |                                            ActionForm tempForm = getSessionDocumentService().getDocumentForm(documentNumber, docFormKey, userSession, request.getRemoteAddr());  | 
  |  480 |    0 |                                            if ( tempForm != null ) { | 
  |  481 |    0 |                                                    form = tempForm;  | 
  |  482 |     | 
                                           }  | 
  |  483 |     | 
                                   }  | 
  |  484 |     | 
     | 
  |  485 |    0 |                                    request.setAttribute(mapping.getAttribute(), form);  | 
  |  486 |    0 |                                    if (form != null) { | 
  |  487 |    0 |                                            return form;  | 
  |  488 |     | 
                                   }  | 
  |  489 |     | 
                           }  | 
  |  490 |     | 
                   }  | 
  |  491 |    0 |                    return form;  | 
  |  492 |     | 
           }  | 
  |  493 |     | 
     | 
  |  494 |     | 
             | 
  |  495 |     | 
     | 
  |  496 |     | 
     | 
  |  497 |     | 
     | 
  |  498 |     | 
     | 
  |  499 |     | 
     | 
  |  500 |     | 
     | 
  |  501 |     | 
     | 
  |  502 |     | 
     | 
  |  503 |     | 
     | 
  |  504 |     | 
           @Override  | 
  |  505 |     | 
           protected ActionForward processActionPerform(final HttpServletRequest request, final HttpServletResponse response, final Action action, final ActionForm form, final ActionMapping mapping) throws IOException, ServletException { | 
  |  506 |     | 
                   try { | 
  |  507 |     | 
                             | 
  |  508 |    0 |                            ActionForward forward = action.execute(mapping, form, request, response);  | 
  |  509 |     | 
     | 
  |  510 |    0 |                            publishMessages(request);  | 
  |  511 |    0 |                            saveMessages(request);  | 
  |  512 |    0 |                            saveAuditErrors(request);  | 
  |  513 |     | 
                             | 
  |  514 |    0 |                            if (form instanceof PojoForm) { | 
  |  515 |    0 |                                    if (((PojoForm)form).getEditableProperties() == null   | 
  |  516 |     | 
                                                   || ((PojoForm)form).getEditableProperties().isEmpty()) { | 
  |  517 |    0 |                                            EditablePropertiesHistoryHolder holder = (EditablePropertiesHistoryHolder) GlobalVariables.getUserSession().getObjectMap().get(KNSConstants.EDITABLE_PROPERTIES_HISTORY_HOLDER_ATTR_NAME);  | 
  |  518 |    0 |                                        if (holder == null) { | 
  |  519 |    0 |                                                holder = new EditablePropertiesHistoryHolder();  | 
  |  520 |     | 
                                       }  | 
  |  521 |     | 
                                             | 
  |  522 |    0 |                                            final String guid = holder.addEditablePropertiesToHistory(((PojoForm)form).getEditableProperties());  | 
  |  523 |    0 |                                        ((PojoForm)form).setActionEditablePropertiesGuid(guid);  | 
  |  524 |    0 |                                        GlobalVariables.getUserSession().addObject(KNSConstants.EDITABLE_PROPERTIES_HISTORY_HOLDER_ATTR_NAME, holder);  | 
  |  525 |     | 
                                   }  | 
  |  526 |     | 
                           }  | 
  |  527 |     | 
                             | 
  |  528 |    0 |                            return forward;  | 
  |  529 |     | 
     | 
  |  530 |    0 |                    } catch (Exception e) { | 
  |  531 |    0 |                            if (e instanceof WrappedRuntimeException) { | 
  |  532 |    0 |                                    e = (Exception) e.getCause();  | 
  |  533 |     | 
                           }  | 
  |  534 |    0 |                            if (e instanceof ValidationException) { | 
  |  535 |     | 
                                     | 
  |  536 |    0 |                                    if (GlobalVariables.getMessageMap().hasNoErrors()) { | 
  |  537 |     | 
     | 
  |  538 |    0 |                                            GlobalVariables.getMessageMap().putError(KNSConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, e.getMessage());  | 
  |  539 |     | 
                                   }  | 
  |  540 |     | 
     | 
  |  541 |    0 |                                    if (form instanceof PojoForm) { | 
  |  542 |    0 |                                            if (((PojoForm)form).getEditableProperties() == null   | 
  |  543 |     | 
                                                           || ((PojoForm)form).getEditableProperties().isEmpty()) { | 
  |  544 |    0 |                                                EditablePropertiesHistoryHolder holder = (EditablePropertiesHistoryHolder) GlobalVariables.getUserSession().getObjectMap().get(KNSConstants.EDITABLE_PROPERTIES_HISTORY_HOLDER_ATTR_NAME);  | 
  |  545 |    0 |                                            if (holder == null) { | 
  |  546 |    0 |                                                    holder = new EditablePropertiesHistoryHolder();  | 
  |  547 |     | 
                                           }  | 
  |  548 |     | 
     | 
  |  549 |    0 |                                                final String guid = holder.addEditablePropertiesToHistory(((PojoForm)form).getEditableProperties());  | 
  |  550 |    0 |                                            ((PojoForm)form).setActionEditablePropertiesGuid(guid);  | 
  |  551 |    0 |                                            GlobalVariables.getUserSession().addObject(KNSConstants.EDITABLE_PROPERTIES_HISTORY_HOLDER_ATTR_NAME, holder);  | 
  |  552 |     | 
                                           }  | 
  |  553 |     | 
                                   }                          | 
  |  554 |     | 
                                     | 
  |  555 |    0 |                                    publishMessages(request);  | 
  |  556 |    0 |                                    return mapping.findForward(RiceConstants.MAPPING_BASIC);  | 
  |  557 |     | 
                           }  | 
  |  558 |     | 
     | 
  |  559 |    0 |                            publishMessages(request);  | 
  |  560 |     | 
     | 
  |  561 |    0 |                            return (processException(request, response, e, form, mapping));  | 
  |  562 |     | 
                   }  | 
  |  563 |     | 
           }  | 
  |  564 |     | 
     | 
  |  565 |     | 
             | 
  |  566 |     | 
     | 
  |  567 |     | 
     | 
  |  568 |     | 
     | 
  |  569 |     | 
     | 
  |  570 |     | 
     | 
  |  571 |     | 
           @Override  | 
  |  572 |     | 
           protected ActionForward processException(HttpServletRequest request, HttpServletResponse response, Exception exception, ActionForm form, ActionMapping mapping) throws IOException, ServletException { | 
  |  573 |    0 |                    ActionForward actionForward = null;  | 
  |  574 |     | 
     | 
  |  575 |     | 
                   try { | 
  |  576 |    0 |                            actionForward = super.processException(request, response, exception, form, mapping);  | 
  |  577 |    0 |                    } catch (IOException e) { | 
  |  578 |    0 |                            logException(e);  | 
  |  579 |    0 |                            throw e;  | 
  |  580 |    0 |                    } catch (ServletException e) { | 
  |  581 |     | 
                             | 
  |  582 |    0 |                            Throwable rootCause = e.getRootCause();  | 
  |  583 |    0 |                            if (rootCause instanceof OjbOperationException) { | 
  |  584 |    0 |                                    OjbOperationException ooe = (OjbOperationException) rootCause;  | 
  |  585 |     | 
     | 
  |  586 |    0 |                                    Throwable subcause = ooe.getCause();  | 
  |  587 |    0 |                                    if (subcause instanceof OptimisticLockException) { | 
  |  588 |    0 |                                            OptimisticLockException ole = (OptimisticLockException) subcause;  | 
  |  589 |     | 
     | 
  |  590 |    0 |                                            StringBuffer message = new StringBuffer(e.getMessage());  | 
  |  591 |     | 
     | 
  |  592 |    0 |                                            Object sourceObject = ole.getSourceObject();  | 
  |  593 |    0 |                                            if (sourceObject != null) { | 
  |  594 |    0 |                                                    message.append(" (sourceObject is "); | 
  |  595 |    0 |                                                    message.append(sourceObject.getClass().getName());  | 
  |  596 |    0 |                                                    message.append(")"); | 
  |  597 |     | 
                                           }  | 
  |  598 |     | 
     | 
  |  599 |    0 |                                            e = new ServletException(message.toString(), rootCause);  | 
  |  600 |     | 
                                   }  | 
  |  601 |     | 
                           }  | 
  |  602 |     | 
     | 
  |  603 |    0 |                            logException(e);  | 
  |  604 |    0 |                            throw e;  | 
  |  605 |    0 |                    }  | 
  |  606 |    0 |                    return actionForward;  | 
  |  607 |     | 
           }  | 
  |  608 |     | 
     | 
  |  609 |     | 
           private void logException(Exception e) { | 
  |  610 |    0 |                    LOG.error("unhandled exception thrown by KualiRequestProcessor.processActionPerform", e); | 
  |  611 |    0 |            }  | 
  |  612 |     | 
     | 
  |  613 |     | 
             | 
  |  614 |     | 
     | 
  |  615 |     | 
     | 
  |  616 |     | 
     | 
  |  617 |     | 
           private void publishMessages(HttpServletRequest request) { | 
  |  618 |    0 |                    MessageMap errorMap = GlobalVariables.getMessageMap();  | 
  |  619 |    0 |                    if (!errorMap.hasNoErrors()) { | 
  |  620 |    0 |                            ErrorContainer errorContainer = new ErrorContainer(errorMap);  | 
  |  621 |     | 
     | 
  |  622 |    0 |                            request.setAttribute("ErrorContainer", errorContainer); | 
  |  623 |    0 |                            request.setAttribute(Globals.ERROR_KEY, errorContainer.getRequestErrors());  | 
  |  624 |    0 |                            request.setAttribute("ErrorPropertyList", errorContainer.getErrorPropertyList()); | 
  |  625 |     | 
                   }  | 
  |  626 |     | 
                     | 
  |  627 |    0 |                    if (errorMap.hasWarnings()) { | 
  |  628 |    0 |                            WarningContainer warningsContainer = new WarningContainer(errorMap);  | 
  |  629 |     | 
                             | 
  |  630 |    0 |                            request.setAttribute("WarningContainer", warningsContainer); | 
  |  631 |    0 |                            request.setAttribute("WarningActionMessages", warningsContainer.getRequestMessages()); | 
  |  632 |    0 |                            request.setAttribute("WarningPropertyList", warningsContainer.getMessagePropertyList()); | 
  |  633 |     | 
                   }  | 
  |  634 |     | 
                     | 
  |  635 |    0 |                    if (errorMap.hasInfo()) { | 
  |  636 |    0 |                            InfoContainer infoContainer = new InfoContainer(errorMap);  | 
  |  637 |     | 
                             | 
  |  638 |    0 |                            request.setAttribute("InfoContainer", infoContainer); | 
  |  639 |    0 |                            request.setAttribute("InfoActionMessages", infoContainer.getRequestMessages()); | 
  |  640 |    0 |                            request.setAttribute("InfoPropertyList", infoContainer.getMessagePropertyList()); | 
  |  641 |     | 
                   }  | 
  |  642 |    0 |            }  | 
  |  643 |     | 
     | 
  |  644 |     | 
             | 
  |  645 |     | 
     | 
  |  646 |     | 
     | 
  |  647 |     | 
     | 
  |  648 |     | 
           private void saveMessages(HttpServletRequest request) { | 
  |  649 |    0 |                    if (!GlobalVariables.getMessageList().isEmpty()) { | 
  |  650 |    0 |                            request.setAttribute(KNSConstants.GLOBAL_MESSAGES, GlobalVariables.getMessageList().toActionMessages());  | 
  |  651 |     | 
                   }  | 
  |  652 |    0 |            }  | 
  |  653 |     | 
     | 
  |  654 |     | 
             | 
  |  655 |     | 
     | 
  |  656 |     | 
     | 
  |  657 |     | 
     | 
  |  658 |     | 
           private void saveAuditErrors(HttpServletRequest request) { | 
  |  659 |    0 |                    if (!GlobalVariables.getAuditErrorMap().isEmpty()) { | 
  |  660 |    0 |                            request.setAttribute(KNSConstants.AUDIT_ERRORS, GlobalVariables.getAuditErrorMap());  | 
  |  661 |     | 
                   }  | 
  |  662 |    0 |            }  | 
  |  663 |     | 
     | 
  |  664 |     | 
             | 
  |  665 |     | 
     | 
  |  666 |     | 
     | 
  |  667 |     | 
     | 
  |  668 |    0 |            @SuppressWarnings("serial") | 
  |  669 |     | 
           private static class WrappedRuntimeException extends RuntimeException { | 
  |  670 |     | 
                   public WrappedRuntimeException(Exception e) { | 
  |  671 |    0 |                            super(e);  | 
  |  672 |    0 |                    }  | 
  |  673 |     | 
           }  | 
  |  674 |     | 
     | 
  |  675 |     | 
             | 
  |  676 |     | 
     | 
  |  677 |     | 
     | 
  |  678 |     | 
           public SessionDocumentService getSessionDocumentService() { | 
  |  679 |    0 |                    if ( sessionDocumentService == null ) { | 
  |  680 |    0 |                            sessionDocumentService = KNSServiceLocatorWeb.getSessionDocumentService();  | 
  |  681 |     | 
                   }  | 
  |  682 |    0 |                    return this.sessionDocumentService;  | 
  |  683 |     | 
           }  | 
  |  684 |     | 
     | 
  |  685 |     | 
             | 
  |  686 |     | 
     | 
  |  687 |     | 
     | 
  |  688 |     | 
           public PlatformTransactionManager getTransactionManager() { | 
  |  689 |    0 |                    if ( transactionManager == null ) { | 
  |  690 |    0 |                            transactionManager = KNSServiceLocatorInternal.getTransactionManager();  | 
  |  691 |     | 
                   }  | 
  |  692 |    0 |                    return this.transactionManager;  | 
  |  693 |     | 
           }  | 
  |  694 |     | 
             | 
  |  695 |     | 
           private ActionForm createNewActionForm(ActionMapping mapping, HttpServletRequest request) { | 
  |  696 |    0 |            String name = mapping.getName();  | 
  |  697 |    0 |            FormBeanConfig config = moduleConfig.findFormBeanConfig(name);  | 
  |  698 |    0 |            if (config == null) { | 
  |  699 |    0 |                log.warn("No FormBeanConfig found under '" + name + "'"); | 
  |  700 |    0 |                return (null);  | 
  |  701 |     | 
           }  | 
  |  702 |    0 |            ActionForm instance = RequestUtils.createActionForm(config, servlet);  | 
  |  703 |    0 |            if ("request".equals(mapping.getScope())) { | 
  |  704 |    0 |                request.setAttribute(mapping.getAttribute(), instance);  | 
  |  705 |     | 
           } else { | 
  |  706 |    0 |                HttpSession session = request.getSession();  | 
  |  707 |    0 |                session.setAttribute(mapping.getAttribute(), instance);  | 
  |  708 |     | 
           }  | 
  |  709 |    0 |            return instance;  | 
  |  710 |     | 
           }  | 
  |  711 |     | 
   }  |