@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;
  }
  public ActionForward clear(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
    roleDocumentForm.setMemberSearchValue("");
    getUiDocumentService()
        .clearRestrictedRoleMembersSearchResults(roleDocumentForm.getRoleDocument());

    KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata();
    if (roleDocumentForm.getMemberRows() != null) {
      memberTableMetadata.jumpToFirstPage(
          roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage());
    }
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
  }
  /**
   * This overridden method ...
   *
   * @see
   *     org.kuali.rice.krad.web.struts.action.KualiDocumentActionBase#loadDocument(org.kuali.rice.krad.web.struts.form.KualiDocumentFormBase)
   */
  @Override
  protected void loadDocument(KualiDocumentFormBase form) throws WorkflowException {
    super.loadDocument(form);

    IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
    setKimType(roleDocumentForm.getRoleDocument().getRoleTypeId(), roleDocumentForm);

    getUiDocumentService().setDelegationMembersInDocument(roleDocumentForm.getRoleDocument());
    getUiDocumentService().setMembersInDocument(roleDocumentForm.getRoleDocument());

    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());
    }
  }
  /**
   * 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());
    }
  }
 /**
  * @see
  *     org.kuali.rice.kns.web.struts.action.KualiTableRenderAction#switchToPage(org.apache.struts.action.ActionMapping,
  *     org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
  *     javax.servlet.http.HttpServletResponse)
  */
 public ActionForward jumpToRoleMember(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm idmForm = (IdentityManagementRoleDocumentForm) form;
   String delegationRoleMemberId = getDelegationRoleMemberToJumpTo(request);
   KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata();
   memberTableMetadata.jumpToPage(
       idmForm.getPageNumberOfRoleMemberId(delegationRoleMemberId),
       idmForm.getMemberRows().size(),
       idmForm.getRecordsPerPage());
   memberTableMetadata.setColumnToSortIndex(memberTableMetadata.getPreviouslySortedColumnIndex());
   idmForm.setAnchor(delegationRoleMemberId);
   return mapping.findForward(RiceConstants.MAPPING_BASIC);
 }
  /**
   * This method returns a list of all active delegates for role members that are inactive
   *
   * @param roleDocumentForm form bean
   * @param roleMembersToConsiderInactive additional role members to consider inactive for the
   *     purposes of this computation
   * @return the active delegates of inactive role members
   */
  private List<RoleDocumentDelegationMember> getActiveDelegatesOfInactiveRoleMembers(
      IdentityManagementRoleDocumentForm roleDocumentForm,
      KimDocumentRoleMember... roleMembersToConsiderInactive) {
    List<KimDocumentRoleMember> roleMembers = roleDocumentForm.getMemberRows();
    List<KimDocumentRoleMember> inactiveRoleMembers = new ArrayList<KimDocumentRoleMember>();
    List<RoleDocumentDelegationMember> activeDelegatesOfInactivatedRoleMembers =
        new ArrayList<RoleDocumentDelegationMember>();

    inactiveRoleMembers.addAll(Arrays.asList(roleMembersToConsiderInactive));

    if (roleMembers != null) {
      for (KimDocumentRoleMember roleMember : roleMembers) {
        if (roleMember != null) {
          if (!roleMember.isActive()) {
            inactiveRoleMembers.add(roleMember);
          }
        }
      }
    }

    for (KimDocumentRoleMember inactiveRoleMember : inactiveRoleMembers) {
      // check if there are delegates for the member being removed
      List<RoleDocumentDelegationMember> delegationMembers =
          roleDocumentForm.getRoleDocument().getDelegationMembers();
      if (delegationMembers != null) {
        for (RoleDocumentDelegationMember delegationMember : delegationMembers) {
          if (delegationMember != null && delegationMember.isActive()) {
            // if the roleMember for this delegation is the same as the inactivatedRoleMember
            if (delegationMember.getRoleMemberId().equals(inactiveRoleMember.getRoleMemberId())) {
              activeDelegatesOfInactivatedRoleMembers.add(delegationMember);
            }
          }
        }
      }
    }
    return activeDelegatesOfInactivatedRoleMembers;
  }