Search in sources :

Example 1 with GcFindGroups

use of edu.internet2.middleware.grouperClient.api.GcFindGroups in project uPortal by Jasig.

the class GrouperEntityGroupStore method searchForGroups.

/* (non-Javadoc)
     * @see org.apereo.portal.groups.IEntityGroupStore#searchForGroups(java.lang.String, int, java.lang.Class)
     */
public EntityIdentifier[] searchForGroups(final String query, final int method, @SuppressWarnings("unchecked") final Class leaftype) {
    //only search for groups
    if (leaftype != IPerson.class) {
        return new EntityIdentifier[] {};
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Searching Grouper for groups matching query: " + query);
    }
    // result groups.
    List<EntityIdentifier> groups = new ArrayList<EntityIdentifier>();
    try {
        // TODO: searches need to be performed against the group display
        // name rather than the group key
        GcFindGroups groupSearch = new GcFindGroups();
        WsQueryFilter filter = new WsQueryFilter();
        //is this an exact search or fuzzy
        if (method == IGroupConstants.IS) {
            filter.setQueryFilterType("FIND_BY_GROUP_NAME_EXACT");
        } else {
            filter.setQueryFilterType("FIND_BY_GROUP_NAME_APPROXIMATE");
        }
        filter.setGroupName(query);
        groupSearch.assignQueryFilter(filter);
        WsFindGroupsResults results = groupSearch.execute();
        if (results != null && results.getGroupResults() != null) {
            for (WsGroup g : results.getGroupResults()) {
                if (validKey(g.getName())) {
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("Retrieved group: " + g.getName());
                    }
                    groups.add(new EntityIdentifier(g.getName(), IEntityGroup.class));
                }
            }
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Returning " + groups.size() + " results for query " + query);
        }
        return groups.toArray(new EntityIdentifier[groups.size()]);
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "search results for query " + query + " and entity type " + leaftype.getCanonicalName() + " : " + e.getMessage());
        return new EntityIdentifier[] {};
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) WsQueryFilter(edu.internet2.middleware.grouperClient.ws.beans.WsQueryFilter) WsFindGroupsResults(edu.internet2.middleware.grouperClient.ws.beans.WsFindGroupsResults) GcFindGroups(edu.internet2.middleware.grouperClient.api.GcFindGroups) ArrayList(java.util.ArrayList) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) EntityIdentifier(org.apereo.portal.EntityIdentifier) GroupsException(org.apereo.portal.groups.GroupsException)

Example 2 with GcFindGroups

use of edu.internet2.middleware.grouperClient.api.GcFindGroups in project uPortal by Jasig.

the class GrouperEntityGroupStore method findGroupFromKey.

/**
     * Find the Grouper group matching the specified key.
     *
     * @param key
     * @return the group or null
     */
protected WsGroup findGroupFromKey(String key) {
    WsGroup wsGroup = null;
    if (key != null) {
        GcFindGroups gcFindGroups = new GcFindGroups();
        gcFindGroups.addGroupName(key);
        WsFindGroupsResults results = gcFindGroups.execute();
        // if no results were returned, return null
        if (results != null && results.getGroupResults() != null && results.getGroupResults().length > 0) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("found group from key " + key + ": " + results.getGroupResults()[0]);
            }
            wsGroup = results.getGroupResults()[0];
        }
    }
    return wsGroup;
}
Also used : WsFindGroupsResults(edu.internet2.middleware.grouperClient.ws.beans.WsFindGroupsResults) GcFindGroups(edu.internet2.middleware.grouperClient.api.GcFindGroups) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup)

Aggregations

GcFindGroups (edu.internet2.middleware.grouperClient.api.GcFindGroups)2 WsFindGroupsResults (edu.internet2.middleware.grouperClient.ws.beans.WsFindGroupsResults)2 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)2 WsQueryFilter (edu.internet2.middleware.grouperClient.ws.beans.WsQueryFilter)1 ArrayList (java.util.ArrayList)1 EntityIdentifier (org.apereo.portal.EntityIdentifier)1 GroupsException (org.apereo.portal.groups.GroupsException)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1