Search in sources :

Example 1 with SizeLimitExceededException

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

the class DirectoryServicesImpl method getSearchResults.

/**
     * convert search results to a AMSearchResults object TODO: Refactor code
     */
private AMSearchResults getSearchResults(SearchResults results, SortKey skey, String[] attrNames, Collator collator, boolean getAllAttrs) throws UMSException {
    TreeMap tm = null;
    TreeSet tmpTreeSet = null;
    if (skey != null) {
        tm = new TreeMap(collator);
        tmpTreeSet = new TreeSet();
    }
    Set set = new OrderedSet();
    Map map = new HashMap();
    int errorCode = AMSearchResults.SUCCESS;
    try {
        if (results != null) {
            while (results.hasMoreElements()) {
                PersistentObject po = results.next();
                String dn = po.getGuid().toString();
                if (tm != null) {
                    Attr attr = po.getAttribute(skey.attributeName);
                    if (attr != null) {
                        String attrValue = attr.getStringValues()[0];
                        Object obj = tm.get(attrValue);
                        if (obj == null) {
                            tm.put(attrValue, dn);
                        } else if (obj instanceof java.lang.String) {
                            TreeSet tmpSet = new TreeSet();
                            tmpSet.add(obj);
                            tmpSet.add(dn);
                            tm.put(attrValue, tmpSet);
                        } else {
                            ((TreeSet) obj).add(dn);
                        }
                    } else {
                        tmpTreeSet.add(dn);
                    }
                } else {
                    set.add(dn);
                }
                AttrSet attrSet = new AttrSet();
                if (attrNames != null) {
                    // Support for multiple return values
                    attrSet = po.getAttributes(attrNames, true);
                } else {
                    /*
                         * Support for multiple return values when attribute
                         * names are not passed as part of the return
                         * attributes. This boolean check is to make sure user
                         * has set the setAllReturnAttributes flag in
                         * AMSearchControl in order to get all attributes or
                         * not.
                         */
                    if (getAllAttrs) {
                        attrSet = po.getAttributes(po.getAttributeNames(), true);
                    }
                }
                map.put(dn, CommonUtils.attrSetToMap(attrSet));
            }
        }
    } catch (SizeLimitExceededException slee) {
        errorCode = AMSearchResults.SIZE_LIMIT_EXCEEDED;
    } catch (TimeLimitExceededException tlee) {
        errorCode = AMSearchResults.TIME_LIMIT_EXCEEDED;
    }
    Integer count = (Integer) results.get(SearchResults.VLVRESPONSE_CONTENT_COUNT);
    int countValue;
    if (count == null) {
        countValue = AMSearchResults.UNDEFINED_RESULT_COUNT;
    } else {
        countValue = count.intValue();
    }
    if (tm != null) {
        Object[] values = tm.values().toArray();
        int len = values.length;
        if (skey.reverse) {
            for (int i = len - 1; i >= 0; i--) {
                Object obj = values[i];
                if (obj instanceof java.lang.String) {
                    set.add(obj);
                } else {
                    set.addAll((Collection) obj);
                }
            }
        } else {
            for (int i = 0; i < len; i++) {
                Object obj = values[i];
                if (obj instanceof java.lang.String) {
                    set.add(obj);
                } else {
                    set.addAll((Collection) obj);
                }
            }
        }
        Iterator iter = tmpTreeSet.iterator();
        while (iter.hasNext()) {
            set.add(iter.next());
        }
    }
    AMSearchResults searchResults = new AMSearchResults(countValue, set, errorCode, map);
    return searchResults;
}
Also used : OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) AttrSet(com.iplanet.services.ldap.AttrSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) PersistentObject(com.iplanet.ums.PersistentObject) TreeMap(java.util.TreeMap) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet) SizeLimitExceededException(com.iplanet.ums.SizeLimitExceededException) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) AMObject(com.iplanet.am.sdk.AMObject) UMSObject(com.iplanet.ums.UMSObject) PersistentObject(com.iplanet.ums.PersistentObject) TimeLimitExceededException(com.iplanet.ums.TimeLimitExceededException) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

AMHashMap (com.iplanet.am.sdk.AMHashMap)1 AMObject (com.iplanet.am.sdk.AMObject)1 AMSearchResults (com.iplanet.am.sdk.AMSearchResults)1 Attr (com.iplanet.services.ldap.Attr)1 AttrSet (com.iplanet.services.ldap.AttrSet)1 PersistentObject (com.iplanet.ums.PersistentObject)1 SizeLimitExceededException (com.iplanet.ums.SizeLimitExceededException)1 TimeLimitExceededException (com.iplanet.ums.TimeLimitExceededException)1 UMSObject (com.iplanet.ums.UMSObject)1 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1