Get all groups that match your string in their name or path.

@param search the group name or path search criteria
@return a List containing matching Group instances
@throws GitLabApiException if any exception occurs
199714
public List<Group> getGroups(String search) throws GitLabApiException {
        return (getGroups(search, getDefaultPerPage()).all());
    }
523864
@Override
    public Iterator findMemberGroups(IEntityGroup eg) throws GroupsException {
        Map groups = new HashMap();
        IEntityGroup group = null;
        for (Iterator itr = findLocalMemberGroups(eg); itr.hasNext(); ) {
            group = (IEntityGroup) itr.next();
            groups.put(group.getKey(), group);
        }

        String[] memberGroupKeys = getGroupStore().findMemberGroupKeys(eg);
        for (int i = 0; i < memberGroupKeys.length; i++) {
            if (!groups.containsKey(memberGroupKeys[i])) {
                group = GroupService.findGroup(memberGroupKeys[i]);
                if (group != null) {
                    groups.put(group.getKey(), group);
                }
            }
        }
        return groups.values().iterator();
    }
75409
@Override
    public EntityIdentifier[] searchForGroups(String query, SearchMethod method, Class leaftype)
            throws GroupsException {

        if (isTreeRefreshRequired()) {
            refreshTree();
        }

        log.debug(
                "Invoking searchForGroups():  query={}, method={}, leaftype=",
                query,
                method,
                leaftype.getName());

        // We only match the IPerson leaf type...
        final IEntityGroup root = getRootGroup();
        if (!leaftype.equals(root.getLeafType())) {
            return new EntityIdentifier[0];
        }

        // We need to escape regex special characters that appear in the query string...
        final String[][] specials =
                new String[][] {
                    /* backslash must come first! */
                    new String[] {"\\", "\\\\"},
                    new String[] {"[", "\\["},
                    /* closing ']' isn't needed b/c it's a normal character w/o a preceding '[' */
                    new String[] {"{", "\\{"},
                    /* closing '}' isn't needed b/c it's a normal character w/o a preceding '{' */
                    new String[] {"^", "\\^"},
                    new String[] {"$", "\\$"},
                    new String[] {".", "\\."},
                    new String[] {"|", "\\|"},
                    new String[] {"?", "\\?"},
                    new String[] {"*", "\\*"},
                    new String[] {"+", "\\+"},
                    new String[] {"(", "\\("},
                    new String[] {")", "\\)"}
                };
        for (String[] s : specials) {
            query = query.replace(s[0], s[1]);
        }

        // Establish the regex pattern to match on...
        String regex;
        switch (method) {
            case DISCRETE:
            case DISCRETE_CI:
                regex = query.toUpperCase();
                break;
            case STARTS_WITH:
            case STARTS_WITH_CI:
                regex = query.toUpperCase() + ".*";
                break;
            case ENDS_WITH:
            case ENDS_WITH_CI:
                regex = ".*" + query.toUpperCase();
                break;
            case CONTAINS:
            case CONTAINS_CI:
                regex = ".*" + query.toUpperCase() + ".*";
                break;
            default:
                String msg = "Unsupported search method:  " + method;
                throw new GroupsException(msg);
        }

        List<EntityIdentifier> rslt = new ArrayList<>();
        for (Map.Entry<String, List<String>> y : groupsTree.getKeysByUpperCaseName().entrySet()) {
            if (y.getKey().matches(regex)) {
                List<String> keys = y.getValue();
                for (String k : keys) {
                    rslt.add(new EntityIdentifier(k, IEntityGroup.class));
                }
            }
        }

        return rslt.toArray(new EntityIdentifier[rslt.size()]);
    }
134300
@Action(semantics = SemanticsOf.SAFE)
    public List<ApplicationRole> findMatching(String search) {
        if (search != null && search.length() > 0 ) {
            return findNameContaining(search);
        }
        return Lists.newArrayList();
    }
660935
private function _fetch_groups($search = null, $mode = 0, $vlv_page = null)
    {
        // reset group search cache
        if ($search !== null && $vlv_page === null) {
            $this->group_search_cache = null;
        }
        // return in-memory cache from previous search results
        else if (is_array($this->group_search_cache) && $vlv_page === null) {
            return $this->group_search_cache;
        }

        // special case: list groups from 'group_filters' config
        if ($vlv_page === null && $search === null && is_array($this->prop['group_filters'])) {
            $groups = array();
            $rcube  = rcube::get_instance();

            // list regular groups configuration as special filter
            if (!empty($this->prop['groups']['filter'])) {
                $id = '__groups__';
                $groups[$id] = array('ID' => $id, 'name' => $rcube->gettext('groups'), 'virtual' => true) + $this->prop['groups'];
            }

            foreach ($this->prop['group_filters'] as $id => $prop) {
                $groups[$id] = $prop + array('ID' => $id, 'name' => ucfirst($id), 'virtual' => true, 'base_dn' => $this->base_dn);
            }

            return $groups;
        }

        if ($this->cache && $search === null && $vlv_page === null && ($groups = $this->cache->get('groups')) !== null) {
            return $groups;
        }

        $base_dn    = $this->groups_base_dn;
        $filter     = $this->prop['groups']['filter'];
        $scope      = $this->prop['groups']['scope'];
        $name_attr  = $this->prop['groups']['name_attr'];
        $email_attr = $this->prop['groups']['email_attr'] ?: 'mail';
        $sort_attrs = $this->prop['groups']['sort'] ? (array)$this->prop['groups']['sort'] : array($name_attr);
        $sort_attr  = $sort_attrs[0];

        $ldap = $this->ldap;

        // use vlv to list groups
        if ($this->prop['groups']['vlv']) {
            $page_size = 200;
            if (!$this->prop['groups']['sort']) {
                $this->prop['groups']['sort'] = $sort_attrs;
            }

            $ldap = clone $this->ldap;
            $ldap->config_set($this->prop['groups']);
            $ldap->set_vlv_page($vlv_page+1, $page_size);
        }

        $props = array('sort' => $this->prop['groups']['sort']);
        $attrs = array_unique(array('dn', 'objectClass', $name_attr, $email_attr, $sort_attr));

        // add search filter
        if ($search !== null) {
            // set wildcards
            $wp = $ws = '';
            if (!empty($this->prop['fuzzy_search']) && !($mode & rcube_addressbook::SEARCH_STRICT)) {
                $ws = '*';
                if (!($mode & rcube_addressbook::SEARCH_PREFIX)) {
                    $wp = '*';
                }
            }
            $filter = "(&$filter($name_attr=$wp" . rcube_ldap_generic::quote_string($search) . "$ws))";
            $props['search'] = $wp . $search . $ws;
        }

        $ldap_data = $ldap->search($base_dn, $filter, $scope, $attrs, $props);

        if ($ldap_data === false) {
            return array();
        }

        $groups          = array();
        $group_sortnames = array();
        $group_count     = $ldap_data->count();

        foreach ($ldap_data as $entry) {
            if (!$entry['dn'])  // DN is mandatory
                $entry['dn'] = $ldap_data->get_dn();

            $group_name = is_array($entry[$name_attr]) ? $entry[$name_attr][0] : $entry[$name_attr];
            $group_id = self::dn_encode($entry['dn']);
            $groups[$group_id]['ID'] = $group_id;
            $groups[$group_id]['dn'] = $entry['dn'];
            $groups[$group_id]['name'] = $group_name;
            $groups[$group_id]['member_attr'] = $this->get_group_member_attr($entry['objectclass']);

            // list email attributes of a group
            for ($j=0; $entry[$email_attr] && $j < $entry[$email_attr]['count']; $j++) {
                if (strpos($entry[$email_attr][$j], '@') > 0)
                    $groups[$group_id]['email'][] = $entry[$email_attr][$j];
            }

            $group_sortnames[] = mb_strtolower($entry[$sort_attr][0]);
        }

        // recursive call can exit here
        if ($vlv_page > 0) {
            return $groups;
        }

        // call recursively until we have fetched all groups
        while ($this->prop['groups']['vlv'] && $group_count == $page_size) {
            $next_page   = $this->_fetch_groups($search, $mode, ++$vlv_page);
            $groups      = array_merge($groups, $next_page);
            $group_count = count($next_page);
        }

        // when using VLV the list of groups is already sorted
        if (!$this->prop['groups']['vlv']) {
            array_multisort($group_sortnames, SORT_ASC, SORT_STRING, $groups);
        }

        // cache this
        if ($this->cache && $search === null) {
            $this->cache->set('groups', $groups);
        }
        else if ($search !== null) {
            $this->group_search_cache = $groups;
        }

        return $groups;
    }
1145790
public List<Label> getLabels(Object projectIdOrPath) throws GitLabApiException {
        return (getLabels(projectIdOrPath, getDefaultPerPage()).all());
    }
263100
private Set<String> getGroups(DirContext context, String callerDn) {
        Set<String> groups = null;
        String groupSearchBase = idStoreDefinition.getGroupSearchBase();
        String groupSearchFilter = idStoreDefinition.getGroupSearchFilter();
        if (groupSearchBase.isEmpty() || groupSearchFilter.isEmpty()) {
            groups = getGroupsByMembership(context, callerDn);
        } else {
            groups = getGroupsByMember(context, callerDn, groupSearchBase, groupSearchFilter);
        }
        return groups;
    }
156021
@Override
    public EntityIdentifier[] searchForEntities(String query, SearchMethod method)
            throws GroupsException {
        boolean allowPartial = true;

        switch (method) {
            case DISCRETE:
                allowPartial = false;
                break;
            case STARTS_WITH:
                query = query + "%";
                break;
            case ENDS_WITH:
                query = "%" + query;
                break;
            case CONTAINS:
                query = "%" + query + "%";
                break;
            default:
                throw new GroupsException("Unknown search type");
        }

        // get the list of matching portlet definitions
        final List<IPortletDefinition> definitions =
                this.portletDefinitionRegistry.searchForPortlets(query, allowPartial);
        if (log.isDebugEnabled()) {
            log.debug("Found " + definitions.size() + " matching definitions for query " + query);
        }

        // initialize an appropriately-sized array of EntityIdentifiers
        final EntityIdentifier[] identifiers = new EntityIdentifier[definitions.size()];

        // add an identifier for each matching portlet
        for (final ListIterator<IPortletDefinition> defIter = definitions.listIterator();
                defIter.hasNext(); ) {
            final IPortletDefinition definition = defIter.next();
            identifiers[defIter.previousIndex()] =
                    new EntityIdentifier(
                            definition.getPortletDefinitionId().getStringId(), this.getType());
        }

        return identifiers;
    }
1008221
@Override
    public IterableResult<Extension> search(ExtensionQuery query) throws SearchException
    {
        return RepositoryUtils.search(query, this.repositories);
    }
55353
public static List<String> match(List<String> patterns, String name) {
        List<String> matches = new ArrayList<String>();
        for (String pattern : patterns) {
            if (match(pattern, name)) {
                matches.add(pattern);
            }
        }
        return matches;
    }
405469
protected function doSearch($search)
    {
        $found = [];
        $result = $this->driver->getFolder(
            $this->container,
            $this->folderPath,
            $this->request->getParameterAsBool('include_files', true),
            $this->request->getParameterAsBool('include_folders', true),
            $this->request->getParameterAsBool('full_tree', false)
        );

        foreach ($result as $rs) {
            if (stripos(basename($rs['path']), $search) !== false) {
                $found[] = $rs;
            }
        }

        return $found;
    }
781347
public final List<PhoneNumberData> getSuggstions(final String psearch, final int plimit) {
    return this.getSuggstions(psearch, plimit, Locale.ROOT);
  }
728166
public List<T> all() throws GitLabApiException {

    	// Make sure that current page is 0, this will ensure the whole list is fetched
    	// regardless of what page the instance is currently on.
    	currentPage = 0;
    	List<T> allItems = new ArrayList<>(totalItems);

    	// Iterate through the pages and append each page of items to the list
    	while (hasNext()) {
    		allItems.addAll(next());
    	}

    	return (allItems);
    }
257172
public void deleteGroup(Object groupIdOrPath) throws GitLabApiException {
        Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
        delete(expectedStatus, null, "groups", getGroupIdOrPath(groupIdOrPath));
    }
1249579
public boolean search(Collection<String> names) {
        while (next()) {
            if (names.contains(getName())) {
                return true;
            }
        }
        return false;
    }
568080
public List<GeoLocation> search(boolean strict, GeoSearch... searches)
    {
        List<GeoLocation> list = new ArrayList<>();
        for (GeoFile gf : files)
        {
            gf.search(strict, list, searches);
        }
        return list;
    }
1155903
private List<LDAPGroup> getGroups(final DirContext ldap, final String dn) throws NamingException
	{
		// Get the DN of all grouos the user is directly/indirectly a member of
		final NamingEnumeration<SearchResult> answer;
		{
			SearchControls search = new SearchControls();

			search.setSearchScope(SearchControls.SUBTREE_SCOPE);
			search.setReturningAttributes(new String[]{"dn"});

			final String searchFilter = String.format(this.ldapGroupFilter, dn);

			answer = ldap.search(ldapSearchBase, searchFilter, search);
		}

		List<LDAPGroup> groups = new ArrayList<>();

		while (answer.hasMoreElements())
		{
			SearchResult sr = answer.next();

			final String groupDN = sr.getNameInNamespace();

			groups.add(dnToLdapGroup(groupDN));
		}

		return groups;
	}