private String redirectToView() {
    StringBuilder redirectUrl = new StringBuilder("BulkEditUserGroups!default.jspa?");

    Iterator<Group> groups = getSelectedGroupsUserHasPermToSee().iterator();
    while (groups.hasNext()) {
      Group group = groups.next();
      redirectUrl.append("selectedGroupsStr=").append(JiraUrlCodec.encode(group.getName()));
      if (groups.hasNext()) redirectUrl.append("&");
    }

    return getRedirect(redirectUrl.toString());
  }
  /**
   * Used to populate the assigned users of the selected groups.<br>
   * Always has the 'All' group which represents all the members of the selected groups.<br>
   * Rest of the users are added under individual group names.
   */
  public Collection getMembersList() {
    if (membersList != null || getSelectedGroupsUserHasPermToSee() == null) return membersList;

    membersList = new ArrayList();
    overloadedGroups = new ArrayList();
    boolean singleGroupSelected = getSelectedGroupsUserHasPermToSee().size() == 1;

    // for each selected group
    GroupOption allGroupOption =
        new GroupOption(getText("admin.bulkeditgroups.all.selected.groups"));
    membersList.add(allGroupOption);
    Iterator<Group> groups = getSelectedGroupsUserHasPermToSee().iterator();
    while (groups.hasNext()) {
      Group group = groups.next();
      // and for each users in that group
      if (group != null) {
        GroupOption groupOption = new GroupOption(group);
        Collection<User> users = groupManager.getDirectUsersInGroup(group);
        Iterator<User> usersOfGroup = users.iterator();
        int count = 0;
        while (usersOfGroup.hasNext()) {
          User user = usersOfGroup.next();
          if (user != null) {
            // increment count
            count++;

            if (count > getMaxUsersDisplayedPerGroup()) {
              overloadedGroups.add(group.getName());
              break;
            }

            if (singleGroupSelected || !isUserInAllGroupsSelected(user)) {
              groupOption.addChildOption(new UserOption(user));
            } else // if more than one group is selected and the user is in all groups add to the
            // main list
            {
              allGroupOption.addChildOption(new UserOption(user));
            }
          }
        }

        if (!groupOption.getChildOptions().isEmpty()) membersList.add(groupOption);
      }
    }
    if (allGroupOption.getChildOptions().isEmpty()) {
      // remove only if empty (must be inserted at top to keep order)
      membersList.remove(allGroupOption);
    }
    return membersList;
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    final FieldVisibilityManager visibilityBean = EasyMock.createMock(FieldVisibilityManager.class);
    EasyMock.expect(
            visibilityBean.isFieldHidden(
                (String) EasyMock.anyObject(), (Issue) EasyMock.anyObject()))
        .andReturn(false)
        .anyTimes();
    EasyMock.replay(visibilityBean);
    ManagerFactory.addService(FieldVisibilityManager.class, visibilityBean);

    originalFactory =
        ComponentManager.getComponentInstanceOfType(FieldClausePermissionChecker.Factory.class);
    ManagerFactory.addService(
        FieldClausePermissionChecker.Factory.class, new MockFieldClausePermissionFactory());
    bob = createMockUser("bob");

    final Group group = addUserToNewGroup(bob, "group");
    carl = createMockUser("carl");

    final GenericValue project =
        UtilsForTests.getTestEntity("Project", EasyMap.build("key", "TST"));

    final PermissionSchemeManager permissionSchemeManager =
        ManagerFactory.getPermissionSchemeManager();
    final GenericValue defaultScheme = permissionSchemeManager.createDefaultScheme();
    final SchemeEntity schemeEntity =
        new SchemeEntity(GroupDropdown.DESC, null, Permissions.BROWSE);
    permissionSchemeManager.createSchemeEntity(defaultScheme, schemeEntity);

    permissionSchemeManager.addSchemeToProject(project, defaultScheme);

    UtilsForTests.getTestEntity("Resolution", EasyMap.build("id", resolutionId));
    // Create two Issues with same comment but different level
    final GenericValue issue1 =
        UtilsForTests.getTestEntity(
            "Issue",
            EasyMap.build(
                "project",
                project.getLong("id"),
                "key",
                "TST-1",
                "resolution",
                resolutionId,
                "summary",
                SUMMARY_BODY));
    UtilsForTests.getTestEntity(
        "Action",
        EasyMap.build(
            "issue",
            issue1.getLong("id"),
            "type",
            ActionConstants.TYPE_COMMENT,
            "body",
            COMMENT_BODY));

    final GenericValue issue2 =
        UtilsForTests.getTestEntity(
            "Issue",
            EasyMap.build(
                "project",
                project.getLong("id"),
                "key",
                "TST-2",
                "resolution",
                resolutionId,
                "summary",
                SUMMARY_BODY));
    UtilsForTests.getTestEntity(
        "Action",
        EasyMap.build(
            "issue",
            issue2.getLong("id"),
            "type",
            ActionConstants.TYPE_COMMENT,
            "body",
            COMMENT_BODY,
            "level",
            group.getName()));

    final GenericValue issue3 =
        UtilsForTests.getTestEntity(
            "Issue",
            EasyMap.build(
                "project",
                project.getLong("id"),
                "key",
                "TST-3",
                "resolution",
                resolutionId,
                "summary",
                ANOTHER_SUMMARY_BODY));
    UtilsForTests.getTestEntity(
        "Action",
        EasyMap.build(
            "issue",
            issue3.getLong("id"),
            "type",
            ActionConstants.TYPE_COMMENT,
            "body",
            ANOTHER_COMMENT_BODY,
            "level",
            group.getName()));

    ManagerFactory.getIndexManager().reIndexAll();
  }
 @Override
 public int compareTo(Group o) {
   return name.compareTo(o.getName());
 }
 public String getString(Group group) {
   if (group == null) {
     return "";
   }
   return group.getName();
 }