001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.channels.groupsmanager.commands;
007:
008: import org.jasig.portal.ChannelRuntimeData;
009: import org.jasig.portal.EntityIdentifier;
010: import org.jasig.portal.channels.groupsmanager.CGroupsManagerSessionData;
011: import org.jasig.portal.channels.groupsmanager.GroupsManagerCommandFactory;
012: import org.jasig.portal.channels.groupsmanager.GroupsManagerXML;
013: import org.jasig.portal.channels.groupsmanager.SearchResultsGroupImpl;
014: import org.jasig.portal.channels.groupsmanager.Utility;
015: import org.jasig.portal.groups.IEntityGroup;
016: import org.jasig.portal.groups.IGroupMember;
017: import org.jasig.portal.services.GroupService;
018: import org.w3c.dom.Document;
019: import org.w3c.dom.Element;
020:
021: /** This command delegates to the GroupsService to find entities requested
022: * by the user.
023: * @author Don Fracapane
024: * @version $Revision: 35664 $
025: */
026: public class Search extends GroupsManagerCommand {
027: private static String grpPrefix = "IEntityGroup::";
028: private static String[] methods;
029: static {
030: methods = new String[5];
031: methods[1] = " is ";
032: methods[2] = " starts with ";
033: methods[3] = " ends with ";
034: methods[4] = " contains ";
035: }
036:
037: /**
038: * put your documentation comment here
039: */
040: public Search() {
041: }
042:
043: /**
044: * This is the public method
045: * @param sessionData
046: * @throws Exception
047: */
048: public void execute(CGroupsManagerSessionData sessionData)
049: throws Exception {
050: Utility.logMessage("DEBUG",
051: "SearchForEntities::execute(): Start");
052: ChannelRuntimeData runtimeData = sessionData.runtimeData;
053: Class type;
054: String grpTypeName = null;
055: EntityIdentifier[] results;
056: String label = null;
057: boolean isGroupSearch;
058: // if present, the command arg will be the ancestor
059: String ancestorKey = getCommandArg(runtimeData);
060: IEntityGroup entGrp = GroupsManagerXML
061: .retrieveGroup(ancestorKey);
062: String query = runtimeData.getParameter("grpQuery");
063: String method = runtimeData.getParameter("grpMethod");
064: int methodInt = Integer.parseInt(method);
065: // For an EntityGroup search, the grpType will have the form of "IEntityGroup::classname"
066: // For an Entity search, the grpType will have the form of "classname"
067: String grpType = runtimeData.getParameter("grpType");
068: if (grpType.startsWith(grpPrefix)) {
069: isGroupSearch = true;
070: grpTypeName = grpType.substring(grpPrefix.length());
071: } else {
072: isGroupSearch = false;
073: grpTypeName = grpType;
074: }
075: type = Class.forName(grpTypeName);
076: if (isGroupSearch) {
077: label = "Group of "
078: + org.jasig.portal.EntityTypes
079: .getDescriptiveName(type) + "s";
080: if (entGrp != null) {
081: results = GroupService.searchForGroups(query,
082: methodInt, type, entGrp);
083: } else {
084: results = GroupService.searchForGroups(query,
085: methodInt, type);
086: }
087: } else {
088: label = org.jasig.portal.EntityTypes
089: .getDescriptiveName(type);
090: if (entGrp != null) {
091: results = GroupService.searchForEntities(query,
092: methodInt, type, entGrp);
093: } else {
094: results = GroupService.searchForEntities(query,
095: methodInt, type);
096: }
097: }
098: Document model = getXmlDoc(sessionData);
099: IEntityGroup sr = new SearchResultsGroupImpl(type);
100: sr.setName("Search Results");
101: sr.setDescription("Search for a " + label + " whose name"
102: + methods[methodInt] + "'" + query + "'");
103: sr.setCreatorID("CGroupsManager");
104: for (int sub = 0; sub < results.length; sub++) {
105: EntityIdentifier entID = results[sub];
106: IGroupMember resultGroup = GroupService
107: .getGroupMember(entID);
108: sr.addMember(resultGroup);
109: }
110: Element searchElem = GroupsManagerXML.getGroupMemberXml(sr,
111: true, null, sessionData.getUnrestrictedData());
112: searchElem.setAttribute("searchResults", "true");
113: model.getDocumentElement().appendChild(searchElem);
114: this .setCommandArg(sessionData.runtimeData, searchElem
115: .getAttribute("id"));
116: GroupsManagerCommandFactory.get("Highlight").execute(
117: sessionData);
118: }
119: }
|