public ActionForward addDelegationMember(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
    RoleDocumentDelegationMember newDelegationMember = roleDocumentForm.getDelegationMember();

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

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

    if (checkDelegationMember(newDelegationMember)
        && KRADServiceLocatorWeb.getKualiRuleService()
            .applyRules(
                new AddDelegationMemberEvent(
                    "", roleDocumentForm.getRoleDocument(), newDelegationMember))) {
      newDelegationMember.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber());
      if (StringUtils.isEmpty(newDelegationMember.getDelegationTypeCode())) {
        newDelegationMember.setDelegationTypeCode(DelegationType.SECONDARY.getCode());
      }
      roleDocumentForm.getRoleDocument().addDelegationMember(newDelegationMember);
      roleDocumentForm.setDelegationMember(
          roleDocumentForm.getRoleDocument().getBlankDelegationMember());
    }
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
  }
 public ActionForward deleteDelegationMember(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
   // Removing, not inactivating -- is this what we really want?
   roleDocumentForm.getRoleDocument().getDelegationMembers().remove(getLineToDelete(request));
   roleDocumentForm.setDelegationMember(
       roleDocumentForm.getRoleDocument().getBlankDelegationMember());
   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());
    }
  }