Search in sources :

Example 1 with SortKey

use of com.iplanet.ums.SortKey in project OpenAM by OpenRock.

the class RemoteServicesImpl method search.

/**
     * Search the Directory
     * 
     * @param token
     *            SSOToken
     * @param entryDN
     *            DN of the entry to start the search with
     * @param searchFilter
     *            search filter
     * @param searchControl
     *            search control defining the VLV indexes and search scope
     * @param attrNames
     *            attributes name
     * @return Set of matching DNs
     */
public AMSearchResults search(SSOToken token, String entryDN, String searchFilter, SearchControl searchControl, String[] attrNames) throws AMException {
    try {
        SortKey[] keys = searchControl.getSortKeys();
        LinkedList sortKeys = new LinkedList();
        for (int i = 0; (keys != null) && (i < keys.length); i++) {
            if (keys[i].reverse) {
                sortKeys.add("true:" + keys[i].attributeName);
            } else {
                // Using "fals" instead of "false" so that it
                // has 4 characters as "true", hence easy to
                // reconstruct SortKey
                sortKeys.add("fals:" + keys[i].attributeName);
            }
        }
        int[] vlvRange = searchControl.getVLVRange();
        if (vlvRange == null) {
            vlvRange = new int[3];
        }
        Set attrNamesSet = MiscUtils.stringArrayToSet(attrNames);
        String tokenID = token.getTokenID().toString();
        Object[] objs = { tokenID, entryDN, searchFilter, sortKeys, new Integer(vlvRange[0]), new Integer(vlvRange[1]), new Integer(vlvRange[2]), searchControl.getVLVJumpTo(), new Integer(searchControl.getTimeOut()), new Integer(searchControl.getMaxResults()), new Integer(searchControl.getSearchScope()), Boolean.valueOf(searchControl.isGetAllReturnAttributesEnabled()), attrNamesSet };
        Map results = (Map) client.send(client.encodeMessage("search3", objs), sessionCookies.getLBCookie(tokenID), null);
        String cString = (String) results.remove(AMSR_COUNT);
        Set dns = (Set) results.remove(AMSR_RESULTS);
        String eString = (String) results.remove(AMSR_CODE);
        int count = 0, errorCode = 0;
        try {
            count = Integer.parseInt(cString);
            errorCode = Integer.parseInt(eString);
        } catch (NumberFormatException nfe) {
            getDebug().error("RemoteServicesImpl.search: caught number " + "format error", nfe);
        }
        return (new AMSearchResults(count, dns, errorCode, results));
    } catch (AMRemoteException amrex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.search2 : entryDN" + entryDN + ";  AMRemoteException caught exception=", amrex);
        }
        throw convertException(amrex);
    } catch (RemoteException rex) {
        getDebug().error("RemoteServicesImpl.search: caught exception=", rex);
        throw new AMException(AMSDKBundle.getString("1000"), "1000");
    } catch (Exception ex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.search2 : entryDN=" + entryDN + ";  caught exception=", ex);
        }
        throw new AMException(AMSDKBundle.getString("1000"), "1000");
    }
}
Also used : Set(java.util.Set) AMException(com.iplanet.am.sdk.AMException) SortKey(com.iplanet.ums.SortKey) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) LinkedList(java.util.LinkedList) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException) AMEventManagerException(com.iplanet.am.sdk.AMEventManagerException) RemoteException(java.rmi.RemoteException) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException) RemoteException(java.rmi.RemoteException) AMHashMap(com.iplanet.am.sdk.AMHashMap) Map(java.util.Map)

Example 2 with SortKey

use of com.iplanet.ums.SortKey in project OpenAM by OpenRock.

the class DirectoryServicesImpl method search.

// RENAME from searchUsingSearchControl => search()
/**
     * Search the Directory
     * 
     * @param token
     *            SSOToken
     * @param entryDN
     *            DN of the entry to start the search with
     * @param searchFilter
     *            search filter
     * @param searchControl
     *            search control defining the VLV indexes and search scope
     * @param attrNames
     *            name of attributes
     * @return Set set of matching DNs
     */
public AMSearchResults search(SSOToken token, String entryDN, String searchFilter, SearchControl searchControl, String[] attrNames) throws AMException {
    AMSearchResults amResults = null;
    try {
        SortKey[] skeys = searchControl.getSortKeys();
        SortKey skey = null;
        if (skeys != null && skeys.length > 0 && skeys[0].attributeName != null) {
            skey = skeys[0];
        }
        String userLocale = CommonUtils.getUserLocale(token);
        if (debug.messageEnabled()) {
            debug.message("DirectoryServicesImpl.search() search with " + "searchcontrol locale = " + userLocale);
        }
        Collator collator = Collator.getInstance(Locale.getLocale(userLocale));
        SearchControl sc;
        if (skey != null) {
            sc = new SearchControl();
            sc.setMaxResults(searchControl.getMaxResults());
            sc.setSearchScope(searchControl.getSearchScope());
            sc.setTimeOut(searchControl.getTimeOut());
        } else {
            sc = searchControl;
        }
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        SearchResults results;
        if (attrNames == null) {
            if (skey == null) {
                results = po.search(searchFilter, sc);
            } else {
                String[] tmpAttrNames = { skey.attributeName };
                results = po.search(searchFilter, tmpAttrNames, sc);
            }
        } else {
            if (skey == null) {
                results = po.search(searchFilter, attrNames, sc);
            } else {
                String[] tmpAttrNames = new String[attrNames.length + 1];
                System.arraycopy(attrNames, 0, tmpAttrNames, 0, attrNames.length);
                tmpAttrNames[attrNames.length] = skey.attributeName;
                results = po.search(searchFilter, tmpAttrNames, sc);
            }
        }
        amResults = getSearchResults(results, skey, attrNames, collator, sc.isGetAllReturnAttributesEnabled());
    } catch (UMSException ue) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.search() with search " + "control entryDN: " + entryDN + " Search Filter: " + searchFilter + " Error occurred: ", ue);
        }
        processInternalException(token, ue, "341");
    }
    return amResults;
}
Also used : UMSException(com.iplanet.ums.UMSException) PersistentObject(com.iplanet.ums.PersistentObject) SortKey(com.iplanet.ums.SortKey) SearchControl(com.iplanet.ums.SearchControl) Guid(com.iplanet.ums.Guid) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) SearchResults(com.iplanet.ums.SearchResults) Collator(java.text.Collator)

Example 3 with SortKey

use of com.iplanet.ums.SortKey in project OpenAM by OpenRock.

the class DirectoryManagerImpl method search2.

public Map search2(String token, String entryDN, String searchFilter, List sortKeys, int startIndex, int beforeCount, int afterCount, String jumpTo, int timeOut, int maxResults, int scope, boolean allAttributes, String[] attrNames) throws AMRemoteException, SSOException, RemoteException {
    // Construct the SortKeys
    initialize();
    SortKey[] keys = null;
    int keysLength = 0;
    if (sortKeys != null && (keysLength = sortKeys.size()) != 0) {
        keys = new SortKey[keysLength];
        for (int i = 0; i < keysLength; i++) {
            String data = (String) sortKeys.get(i);
            keys[i] = new SortKey();
            keys[i].reverse = data.startsWith("true:");
            keys[i].attributeName = data.substring(5);
        }
    }
    // Construct SearchControl
    SearchControl sc = new SearchControl();
    if (keys != null) {
        sc.setSortKeys(keys);
    }
    if (jumpTo == null) {
        sc.setVLVRange(startIndex, beforeCount, afterCount);
    } else {
        sc.setVLVRange(jumpTo, beforeCount, afterCount);
    }
    sc.setTimeOut(timeOut);
    sc.setMaxResults(maxResults);
    sc.setSearchScope(scope);
    sc.setAllReturnAttributes(allAttributes);
    // Perform the search
    try {
        AMSearchResults results = dsServices.search(tm.createSSOToken(token), entryDN, searchFilter, sc, attrNames);
        // Convert results to Map
        Map answer = results.getResultAttributes();
        if (answer == null) {
            answer = new HashMap();
        }
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_COUNT, Integer.toString(results.getTotalResultCount()));
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_RESULTS, results.getSearchResults());
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_CODE, Integer.toString(results.getErrorCode()));
        return (answer);
    } catch (AMException amex) {
        if (debug.messageEnabled()) {
            debug.message("DMI::search(with SearchControl):  entryDN=" + entryDN + "the exception is: " + amex);
        }
        throw convertException(amex);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AMException(com.iplanet.am.sdk.AMException) SortKey(com.iplanet.ums.SortKey) SearchControl(com.iplanet.ums.SearchControl) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 4 with SortKey

use of com.iplanet.ums.SortKey in project OpenAM by OpenRock.

the class DirectoryManagerImpl method search3.

public Map search3(String token, String entryDN, String searchFilter, List sortKeys, int startIndex, int beforeCount, int afterCount, String jumpTo, int timeOut, int maxResults, int scope, boolean allAttributes, Set attrNamesSet) throws AMRemoteException, SSOException, RemoteException {
    // Construct the SortKeys
    initialize();
    SortKey[] keys = null;
    int keysLength = 0;
    if (sortKeys != null && (keysLength = sortKeys.size()) != 0) {
        keys = new SortKey[keysLength];
        for (int i = 0; i < keysLength; i++) {
            String data = (String) sortKeys.get(i);
            keys[i] = new SortKey();
            keys[i].reverse = data.startsWith("true:");
            keys[i].attributeName = data.substring(5);
        }
    }
    // Construct SearchControl
    SearchControl sc = new SearchControl();
    if (keys != null) {
        sc.setSortKeys(keys);
    }
    if (jumpTo == null) {
        sc.setVLVRange(startIndex, beforeCount, afterCount);
    } else {
        sc.setVLVRange(jumpTo, beforeCount, afterCount);
    }
    sc.setTimeOut(timeOut);
    sc.setMaxResults(maxResults);
    sc.setSearchScope(scope);
    sc.setAllReturnAttributes(allAttributes);
    String[] attrNames = new String[attrNamesSet.size()];
    attrNames = (String[]) attrNamesSet.toArray(attrNames);
    // Perform the search
    try {
        AMSearchResults results = dsServices.search(tm.createSSOToken(token), entryDN, searchFilter, sc, attrNames);
        // Convert results to Map
        Map answer = results.getResultAttributes();
        if (answer == null) {
            answer = new HashMap();
        }
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_COUNT, Integer.toString(results.getTotalResultCount()));
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_RESULTS, results.getSearchResults());
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_CODE, Integer.toString(results.getErrorCode()));
        return (answer);
    } catch (AMException amex) {
        if (debug.messageEnabled()) {
            debug.message("DMI::search(with SearchControl3): entryDN=" + entryDN + "the exception is: " + amex);
        }
        throw convertException(amex);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AMException(com.iplanet.am.sdk.AMException) SortKey(com.iplanet.ums.SortKey) SearchControl(com.iplanet.ums.SearchControl) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Aggregations

AMSearchResults (com.iplanet.am.sdk.AMSearchResults)4 SortKey (com.iplanet.ums.SortKey)4 AMException (com.iplanet.am.sdk.AMException)3 SearchControl (com.iplanet.ums.SearchControl)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)1 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)1 AMHashMap (com.iplanet.am.sdk.AMHashMap)1 SSOException (com.iplanet.sso.SSOException)1 Guid (com.iplanet.ums.Guid)1 PersistentObject (com.iplanet.ums.PersistentObject)1 SearchResults (com.iplanet.ums.SearchResults)1 UMSException (com.iplanet.ums.UMSException)1 RemoteException (java.rmi.RemoteException)1 Collator (java.text.Collator)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1