Search in sources :

Example 1 with WsQueryFilter

use of edu.internet2.middleware.grouperClient.ws.beans.WsQueryFilter 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 WsQueryFilter

use of edu.internet2.middleware.grouperClient.ws.beans.WsQueryFilter 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)
     */
@Override
public EntityIdentifier[] searchForGroups(final String query, final SearchMethod 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 == SearchMethod.DISCRETE_CI) || (method == SearchMethod.DISCRETE)) {
            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)

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)2 ArrayList (java.util.ArrayList)2 EntityIdentifier (org.apereo.portal.EntityIdentifier)2 GroupsException (org.apereo.portal.groups.GroupsException)2 IEntityGroup (org.apereo.portal.groups.IEntityGroup)2