/**
   * This overridden method ...
   *
   * @see
   *     org.kuali.rice.krad.web.struts.action.KualiDocumentActionBase#createDocument(org.kuali.rice.krad.web.struts.form.KualiDocumentFormBase)
   */
  @Override
  protected void createDocument(KualiDocumentFormBase form) throws WorkflowException {
    super.createDocument(form);
    IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;

    if (roleDocumentForm.getRoleId() == null) {
      roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType());
      roleDocumentForm.getRoleDocument().initializeDocumentForNewRole();
      roleDocumentForm.setRoleId(roleDocumentForm.getRoleDocument().getRoleId());
      // roleDocumentForm.setKimType(KimApiServiceLocator.getKimTypeInfoService().getKimType(roleDocumentForm.getRoleDocument().getRoleTypeId()));
    } else {
      loadRoleIntoDocument(roleDocumentForm.getRoleId(), roleDocumentForm);
    }

    roleDocumentForm.setMember(roleDocumentForm.getRoleDocument().getBlankMember());
    roleDocumentForm.setDelegationMember(
        roleDocumentForm.getRoleDocument().getBlankDelegationMember());

    KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata();
    if (roleDocumentForm.getMemberRows() != null) {
      memberTableMetadata.jumpToFirstPage(
          roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage());
    }
  }
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
    if (roleDocumentForm.getRoleId() == null) {
      String roleId = request.getParameter(KimConstants.PrimaryKeyConstants.SUB_ROLE_ID);
      roleDocumentForm.setRoleId(roleId);
    }

    KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata();
    if (roleDocumentForm.getRoleDocument() != null && roleDocumentForm.getMemberRows() != null) {
      memberTableMetadata.jumpToPage(
          memberTableMetadata.getViewedPageNumber(),
          roleDocumentForm.getMemberRows().size(),
          roleDocumentForm.getRecordsPerPage());
      // KULRICE-3972: need to be able to sort by column header like on lookups when editing large
      // roles and groups
      memberTableMetadata.sort(
          roleDocumentForm.getMemberRows(), roleDocumentForm.getRecordsPerPage());
    }

    // KULRICE-4762: active delegates of "inactivated" role members cause validation problems
    ActionForward forward =
        promptForAffectedDelegates(mapping, form, request, response, roleDocumentForm);
    // if we need to prompt the user due to affected delegates, do so:
    if (forward != null) {
      return forward;
    }

    forward = super.execute(mapping, roleDocumentForm, request, response);

    roleDocumentForm.setCanAssignRole(validAssignRole(roleDocumentForm.getRoleDocument()));
    if (KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(
        roleDocumentForm.getRoleDocument().getKimType())) {
      roleDocumentForm.setCanModifyAssignees(false);
    }
    GlobalVariables.getUserSession()
        .addObject(
            KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY,
            roleDocumentForm.getRoleDocument());
    return forward;
  }