/**
   * 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());
    }
  }
  public ActionForward addMember(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
    KimDocumentRoleMember newMember = roleDocumentForm.getMember();

    // See if possible to add with just Group Details filled in (not returned from lookup)
    if (StringUtils.equals(
            newMember.getMemberTypeCode(),
            KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode())
        && StringUtils.isEmpty(newMember.getMemberId())
        && !newMember.isMemberNameNull()
        && !newMember.isMemberNameSpaceCodeNull()) {
      Group tempGroup =
          KimApiServiceLocator.getGroupService()
              .getGroupByNamespaceCodeAndName(
                  newMember.getMemberNamespaceCode(), newMember.getMemberName());
      if (tempGroup != null) {
        newMember.setMemberId(tempGroup.getId());
      }
    }

    // See if possible to grab details for Principal
    if (StringUtils.equals(
            newMember.getMemberTypeCode(),
            KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode())
        && StringUtils.isEmpty(newMember.getMemberId())
        && StringUtils.isNotEmpty(newMember.getMemberName())) {
      Principal principal =
          KimApiServiceLocator.getIdentityService()
              .getPrincipalByPrincipalName(newMember.getMemberName());
      if (principal != null) {
        newMember.setMemberId(principal.getPrincipalId());
        String fullName = checkMemberFullName(principal.getPrincipalId());
        if (fullName != null) {
          newMember.setMemberFullName(fullName);
        }
      }
    } else if (StringUtils.equals(
            newMember.getMemberTypeCode(),
            KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode())
        && StringUtils.isNotEmpty(newMember.getMemberId())
        && StringUtils.isNotEmpty(newMember.getMemberName())) {
      String fullName = checkMemberFullName(newMember.getMemberId());
      if (fullName != null) {
        newMember.setMemberFullName(fullName);
      }
    }

    if (checkKimDocumentRoleMember(newMember)
        && KRADServiceLocatorWeb.getKualiRuleService()
            .applyRules(new AddMemberEvent("", roleDocumentForm.getRoleDocument(), newMember))) {
      newMember.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber());
      roleDocumentForm.getRoleDocument().addMember(newMember);
      roleDocumentForm.setMember(roleDocumentForm.getRoleDocument().getBlankMember());
    }
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
  }