use of com.iplanet.ums.TimeLimitExceededException 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;
}
Aggregations