/**
   * This method gets called upon navigation to Custom Data tab.
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   */
  public ActionForward institutionalProposalActions(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String command = request.getParameter(KewApiConstants.COMMAND_PARAMETER);
    if (StringUtils.isNotEmpty(command) && KewApiConstants.DOCSEARCH_COMMAND.equals(command)) {
      loadDocumentInForm(request, (InstitutionalProposalForm) form);
    }

    return mapping.findForward(Constants.MAPPING_INSTITUTIONAL_PROPOSAL_ACTIONS_PAGE);
  }
  /**
   * This method gets called upon navigation to ProtocolBase Actions tab.
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   */
  public ActionForward protocolActions(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    // for protocol lookup copy link - rice 1.1 need this
    ProtocolFormBase protocolForm = (ProtocolFormBase) form;
    String command = request.getParameter("command");
    if (KewApiConstants.DOCSEARCH_COMMAND.equals(command)) {
      String docIdRequestParameter = request.getParameter(KRADConstants.PARAMETER_DOC_ID);
      Document retrievedDocument =
          KRADServiceLocatorWeb.getDocumentService().getByDocumentHeaderId(docIdRequestParameter);
      protocolForm.setDocument(retrievedDocument);
      request.setAttribute(KRADConstants.PARAMETER_DOC_ID, docIdRequestParameter);
    }
    // make sure current submission is displayed when navigate to action page.
    protocolForm.getActionHelper().setCurrentSubmissionNumber(-1);
    protocolForm.getActionHelper().prepareView();
    protocolForm.getActionHelper().prepareCommentsView();

    // When a user selects the Questionnaires tab, empty answerHeaders are generated and saved to
    // the database so that subsequent methods relying
    // on that persisted data have it available to render panels.  Make Protocol Actions tab work in
    // this same manner so it's sub-tab
    // Print ==> Questionnaires will render when a user enters a protocol but does not select the
    // Questionnaire tab to answer the questions.
    protocolForm.getQuestionnaireHelper().prepareView();
    protocolForm.getQuestionnaireHelper().populateAnswers();
    protocolForm.getQuestionnaireHelper().setQuestionnaireActiveStatuses();
    Document document = protocolForm.getDocument();
    List<AnswerHeader> answerHeaders = protocolForm.getQuestionnaireHelper().getAnswerHeaders();
    if (applyRules(new SaveQuestionnaireAnswerEvent(document, answerHeaders))
        && applyRules(new SaveProtocolQuestionnaireEvent(document, answerHeaders))) {
      protocolForm.getQuestionnaireHelper().preSave();
      getBusinessObjectService().save(answerHeaders);
    }

    return branchToPanelOrNotificationEditor(
        mapping, protocolForm, getProtocolActionsForwardNameHook());
  }
  @Override
  @RequestMapping(params = "methodToCall=docHandler")
  public ModelAndView docHandler(
      @ModelAttribute("KualiForm") DocumentFormBase formBase,
      BindingResult result,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // TODO getting double view if we call base, not sure how to handle
    // so pasting in superclass code
    // super.docHandler(formBase, request, response);
    // * begin copy/paste from the base
    MaintenanceDocumentForm form = (MaintenanceDocumentForm) formBase;

    // in all of the following cases we want to load the document
    if (ArrayUtils.contains(DOCUMENT_LOAD_COMMANDS, form.getCommand()) && form.getDocId() != null) {
      try {
        loadDocument(form);
        OlePersistableBusinessObjectBase olePersistableBusinessObjectBase =
            (OlePersistableBusinessObjectBase)
                form.getDocument().getNewMaintainableObject().getDataObject();
        olePersistableBusinessObjectBase.setAlertBoList(
            alertService.retrieveAlertList(form.getDocument().getDocumentNumber()));
      } catch (UnknownDocumentIdException udie) {
        ConfigurationService kualiConfigurationService =
            CoreApiServiceLocator.getKualiConfigurationService();
        StringBuffer sb = new StringBuffer();
        sb.append(kualiConfigurationService.getPropertyValueAsString(KRADConstants.KRAD_URL_KEY));
        sb.append(
            kualiConfigurationService.getPropertyValueAsString(
                KRADConstants.KRAD_INITIATED_DOCUMENT_URL_KEY));
        Properties props = new Properties();
        props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START);
        GlobalVariables.getUifFormManager().removeSessionForm(form); // removeForm(form);
        return performRedirect(new InitiatedDocumentInfoForm(), sb.toString(), props);
      }
    } else if (KewApiConstants.INITIATE_COMMAND.equals(form.getCommand())) {
      createDocument(form);
    } else {
      LOG.error("docHandler called with invalid parameters");
      throw new IllegalArgumentException("docHandler called with invalid parameters");
    }
    // * end copy/paste from the base

    if (KewApiConstants.ACTIONLIST_COMMAND.equals(form.getCommand())
        || KewApiConstants.DOCSEARCH_COMMAND.equals(form.getCommand())
        || KewApiConstants.SUPERUSER_COMMAND.equals(form.getCommand())
        || KewApiConstants.HELPDESK_ACTIONLIST_COMMAND.equals(form.getCommand())
            && form.getDocId() != null) {
      // TODO: set state in view
      // form.setReadOnly(true);
      form.setMaintenanceAction(
          (form.getDocument()).getNewMaintainableObject().getMaintenanceAction());

      // Retrieving the FileName from BO table
      Maintainable tmpMaintainable = form.getDocument().getNewMaintainableObject();
      if (tmpMaintainable.getDataObject() instanceof PersistableAttachment) {
        PersistableAttachment bo =
            (PersistableAttachment)
                getBusinessObjectService()
                    .retrieve((PersistableBusinessObject) tmpMaintainable.getDataObject());
        if (bo != null) {
          request.setAttribute("fileName", bo.getFileName());
        }
      }
    } else if (KewApiConstants.INITIATE_COMMAND.equals(form.getCommand())) {
      // form.setReadOnly(false);
      setupMaintenance(form, request, KRADConstants.MAINTENANCE_NEW_ACTION);
    } else {
      LOG.error("We should never have gotten to here");
      throw new IllegalArgumentException("docHandler called with invalid parameters");
    }

    return getUIFModelAndView(form);
  }