public ActionForward deleteMember(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
    KimDocumentRoleMember inactivatedRoleMember =
        roleDocumentForm.getRoleDocument().getModifiedMembers().get(getLineToDelete(request));

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

    Calendar cal = Calendar.getInstance();
    inactivatedRoleMember.setActiveToDate(new Timestamp(cal.getTimeInMillis()));

    roleDocumentForm
        .getRoleDocument()
        .getModifiedMembers()
        .set(getLineToDelete(request), inactivatedRoleMember);
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
  }
 protected void loadRoleIntoDocument(
     String roleId, IdentityManagementRoleDocumentForm roleDocumentForm) {
   Role role = KimApiServiceLocator.getRoleService().getRole(roleId);
   roleDocumentForm
       .getRoleDocument()
       .setMemberMetaDataTypeToSort(
           roleDocumentForm.getMemberTableMetadata().getColumnToSortIndex());
   getUiDocumentService().loadRoleDoc(roleDocumentForm.getRoleDocument(), role);
 }
 public ActionForward changeMemberTypeCode(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
   roleDocumentForm.getMember().setMemberId("");
   return refresh(mapping, roleDocumentForm, request, response);
 }
 public ActionForward deletePermission(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
   roleDocumentForm.getRoleDocument().getPermissions().remove(getLineToDelete(request));
   return mapping.findForward(RiceConstants.MAPPING_BASIC);
 }
 public ActionForward sort(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
   KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata();
   memberTableMetadata.setSwitchToPageNumber(0);
   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);
 }
 protected void setKimType(String kimTypeId, IdentityManagementRoleDocumentForm roleDocumentForm) {
   if (StringUtils.isNotBlank(kimTypeId)) {
     roleDocumentForm.setKimType(
         KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId));
     if (roleDocumentForm.getRoleDocument() != null) {
       roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType());
     }
   } else if (roleDocumentForm.getRoleDocument() != null
       && StringUtils.isNotBlank(roleDocumentForm.getRoleDocument().getRoleTypeId())) {
     roleDocumentForm.setKimType(
         KimApiServiceLocator.getKimTypeInfoService()
             .getKimType(roleDocumentForm.getRoleDocument().getRoleTypeId()));
     roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType());
   }
 }
 public ActionForward editMember(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
   KimDocumentRoleMember roleMemberToEdit =
       roleDocumentForm.getRoleDocument().getMembers().get(getLineToEdit(request));
   KimDocumentRoleMember copiedMember =
       (KimDocumentRoleMember) SerializationUtils.deepCopy(roleMemberToEdit);
   roleDocumentForm.getRoleDocument().getModifiedMembers().add(copiedMember);
   roleDocumentForm.getRoleDocument().getMembers().remove(roleMemberToEdit);
   return mapping.findForward(RiceConstants.MAPPING_BASIC);
 }
 public ActionForward search(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
   String memberSearchValue = roleDocumentForm.getMemberSearchValue();
   if (memberSearchValue != null && !memberSearchValue.isEmpty()) {
     memberSearchValue = memberSearchValue.replaceAll("[%*]", "");
     getUiDocumentService()
         .loadRoleMembersBasedOnSearch(roleDocumentForm.getRoleDocument(), memberSearchValue);
   } else {
     clear(mapping, form, request, response);
   }
   return mapping.findForward(RiceConstants.MAPPING_BASIC);
 }
  public ActionForward addResponsibility(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
    KimDocumentRoleResponsibility newResponsibility = roleDocumentForm.getResponsibility();
    if (newResponsibility != null
        && StringUtils.isNotBlank(newResponsibility.getResponsibilityId())) {
      ResponsibilityBo responsibilityImpl =
          KradDataServiceLocator.getDataObjectService()
              .find(ResponsibilityBo.class, newResponsibility.getResponsibilityId());
      newResponsibility.setKimResponsibility(responsibilityImpl);
    }

    if (KRADServiceLocatorWeb.getKualiRuleService()
        .applyRules(
            new AddResponsibilityEvent(
                "", roleDocumentForm.getRoleDocument(), newResponsibility))) {
      if (newResponsibility != null) {
        newResponsibility.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber());
      }
      roleDocumentForm.getRoleDocument().addResponsibility(newResponsibility);
      roleDocumentForm.setResponsibility(new KimDocumentRoleResponsibility());
      roleDocumentForm.getRoleDocument().updateMembers(newResponsibility);
    }
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
  }
 public ActionForward changeDelegationMemberTypeCode(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
   KimDocumentRoleMember roleMember =
       roleDocumentForm
           .getRoleDocument()
           .getMember(roleDocumentForm.getDelegationMember().getRoleMemberId());
   if (roleMember != null) {
     RoleDocumentDelegationMemberQualifier delegationMemberQualifier;
     for (KimDocumentRoleQualifier roleQualifier : roleMember.getQualifiers()) {
       delegationMemberQualifier =
           roleDocumentForm.getDelegationMember().getQualifier(roleQualifier.getKimAttrDefnId());
       delegationMemberQualifier.setAttrVal(roleQualifier.getAttrVal());
     }
   }
   return refresh(mapping, roleDocumentForm, request, response);
 }
  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);
  }
  /**
   * 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;
  }
  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);
  }
 public ActionForward addPermission(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form;
   KimDocumentRolePermission newPermission = roleDocumentForm.getPermission();
   if (KRADServiceLocatorWeb.getKualiRuleService()
       .applyRules(
           new AddPermissionEvent("", roleDocumentForm.getRoleDocument(), newPermission))) {
     newPermission.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber());
     newPermission.setRoleId(roleDocumentForm.getRoleDocument().getRoleId());
     roleDocumentForm.getRoleDocument().getPermissions().add(newPermission);
     roleDocumentForm.setPermission(new KimDocumentRolePermission());
   }
   return mapping.findForward(RiceConstants.MAPPING_BASIC);
 }
  /**
   * If there are active delegates of an "inactivated" role member, return an ActionForward to
   * prompt the user letting them know that the delegates will be "inactivated" too if they proceed.
   *
   * <p>Also, if the user has already responded to the question and the response was (1) "Yes", then
   * return null, signifying that we can go ahead and take the needed action to "inactivate" the
   * delegates; or (2) "No", then return a basic forward that will cancel further action.
   */
  private ActionForward getAffectedDelegatesQuestionActionForward(
      List<RoleDocumentDelegationMember> activeDelegatesOfInactiveRoleMembers,
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response,
      IdentityManagementRoleDocumentForm roleDocumentForm)
      throws Exception {

    if (activeDelegatesOfInactiveRoleMembers.size() > 0) {
      Object question = getQuestion(request);
      // logic for delegates question
      if (question == null || !REMOVE_AFFECTED_DELEGATES_QUESTION_ID.equals(question)) {
        return performQuestionWithoutInput(
            mapping,
            form,
            request,
            response,
            REMOVE_AFFECTED_DELEGATES_QUESTION_ID,
            getKualiConfigurationService()
                .getPropertyValueAsString(
                    RiceKeyConstants.QUESTION_ACTIVE_DELEGATES_FOR_INACTIVE_MEMBERS),
            KRADConstants.CONFIRMATION_QUESTION,
            roleDocumentForm.getMethodToCall(),
            StringUtils.EMPTY);
      }
      Object buttonClicked = request.getParameter(KRADConstants.QUESTION_CLICKED_BUTTON);
      if ((REMOVE_AFFECTED_DELEGATES_QUESTION_ID.equals(question))
          && ConfirmationQuestion.YES.equals(buttonClicked)) {
        // the question was answered in the affirmative.
        // fall through, no special mapping to return
      } else {
        // NO was clicked ... what to do?  Return basic mapping without "inactivating" anything
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
      }
    }

    return null;
  }
 /**
  * @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 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());
    }
  }
  @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;
  }
  /**
   * 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());
    }
  }