When writing customizations using the Strategy Java Web SDK, there may be a need to locate a user based on their login ID. This technical document will clarify the process to create a WebSearch object that will locate a user based on their login ID.
The WebSearch object is the main tool for searching the metadata. The code below searches the metadata for a user with a given login ID, searchString:
WebSearch webSearch=objectSource.getNewSearchObject();
webSearch.setSearchFlags(EnumDSSXMLSearchFlags.DssXmlSearchNameWildCard+EnumDSSXMLSearchFlags.DssXmlSearchRootRecursive);
//Use a simple list to restrict the search to only User Objects
SimpleList searchTypes = webSearch.types();
Integer type=new Integer(EnumDSSXMLObjectTypes.DssXmlTypeUser);
searchTypes.add(type);
//Note: Use the Abbreviation Pattern, not the Name Pattern to search on Login ID
webSearch.setAbbreviationPattern(searchString);
//set the Domain to search the entire Repository
webSearch.setDomain( EnumDSSXMLSearchDomain.DssXmlSearchDomainRepository );
webSearch.setAsync(false);
WebObjectInfo objectInfo = null;
//Execute the search
try {
webSearch.submit();
if (webSearch.getResults().isEmpty())
System.out.println("No user by name "+searchString);
else {
objectInfo = webSearch.getResults().get(0);
System.out.println("Found user: " + objectInfo.getDisplayName());
}
}
catch (Exception e){
System.out.println("Search failed: "+e);
}
To create a WebSearch object, the user simply needs to insert the following line in any java class where they are using Strategy objects:
WebSearch webSearch=objectSource.getNewSearchObject();
There are two ways that the above code varies from a standard search:
Customization Warning:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.