EntityIdentifier[] results;
String label = null;
boolean isGroupSearch;
// if present, the command arg will be the ancestor
String ancestorKey = getCommandArg(runtimeData);
IEntityGroup entGrp = GroupsManagerXML.retrieveGroup(ancestorKey);
String query = runtimeData.getParameter("grpQuery");
String method = runtimeData.getParameter("grpMethod");
int methodInt = Integer.parseInt(method);
// For an EntityGroup search, the grpType will have the form of "IEntityGroup::classname"
// For an Entity search, the grpType will have the form of "classname"
String grpType = runtimeData.getParameter("grpType");
if (grpType.startsWith(grpPrefix)) {
isGroupSearch = true;
grpTypeName = grpType.substring(grpPrefix.length());
}
else {
isGroupSearch = false;
grpTypeName = grpType;
}
type = Class.forName(grpTypeName);
if (isGroupSearch) {
label = "Group of " + org.jasig.portal.EntityTypes.getDescriptiveName(type) +
"s";
if (entGrp != null) {
results = GroupService.searchForGroups(query, methodInt, type, entGrp);
}
else {
results = GroupService.searchForGroups(query, methodInt, type);
}
}
else {
label = org.jasig.portal.EntityTypes.getDescriptiveName(type);
if (entGrp != null) {
results = GroupService.searchForEntities(query, methodInt, type, entGrp);
}
else {
results = GroupService.searchForEntities(query, methodInt, type);
}
}
Document model = getXmlDoc(sessionData);
IEntityGroup sr = new SearchResultsGroupImpl(type);
sr.setName("Search Results");
sr.setDescription("Search for a " + label + " whose name" + methods[methodInt] + "'" + query + "'");
sr.setCreatorID("CGroupsManager");
for (int sub = 0; sub < results.length; sub++) {
EntityIdentifier entID = results[sub];
IGroupMember resultGroup = GroupService.getGroupMember(entID);
sr.addMember(resultGroup);
}
Element searchElem = GroupsManagerXML.getGroupMemberXml(sr, true, null, sessionData.getUnrestrictedData());
searchElem.setAttribute("searchResults", "true");
model.getDocumentElement().appendChild(searchElem);
this.setCommandArg(sessionData.runtimeData, searchElem.getAttribute("id"));