To search for objects by name, you normally use a combination of find qualifiers and name patterns. Find qualifiers affect sorting and pattern matching. Name patterns specify the strings to be searched. The BusinessQueryManagerImpl.findObjects method takes a collection of FindQualifier objects as its second argument and takes a collection of name patterns as its third argument. The method signature is as follows:
public BulkResponse findObjects(java.lang.String objectType, java.util.Collection findQualifiers, java.util.Collection namePatterns, java.util.Collection classifications, java.util.Collection specifications, java.util.Collection externalIdentifiers, java.util.Collection externalLinks) throws JAXRException
For the first argument, the object type, you normally specify one of a set of string constants that are defined in the LifeCycleManager interface.
You can use wildcards in a name pattern. Use percent signs (%) to specify that the search string occurs at the beginning, middle, or end of the object name. Here are some examples:
Specify nor% to return strings that start with Nor or nor, such as North and northern.
Specify %off% to return strings that contain the string off, such as Coffee.
Specify %ica to return strings that end with ica, such as America.
You can also use an underscore (_) as a wildcard to match a single character. For example, the search string _us_ would match objects named Aus1 and Bus3.
For example, the following code fragment finds all the organizations in the Registry whose names begin with a specified string, searchString, and sorts them in alphabetical order.
// Define find qualifiers and name patterns Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC); Collection namePatterns = new ArrayList(); namePatterns.add(searchString + "%"); // Find organizations with name that starts with searchString BulkResponse response = bqm.findObjects("Organization", findQualifiers, namePatterns, null, null, null, null); Collection orgs = response.getCollection();
The findObjects method is not case-sensitive, unless you specify FindQualifier.CASE_SENSITIVE_MATCH. In the previous fragment, the first argument could be either "Organization" or "organization", and the name pattern matches names regardless of case.
The following code fragment performs a case-sensitive search for all registry objects whose names contain the string searchString and sorts the objects in alphabetical order.
Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC); Collection namePatterns = new ArrayList(); namePatterns.add("%" + searchString + "%"); // Find objects with name that contains searchString BulkResponse response = bqm.findObjects("RegistryObject", findQualifiers, namePatterns, null, null, null, null); Collection orgs = response.getCollection();
The percent sign matches any number of characters in the name. To match a single character, use the underscore (_). For example, to match both “Arg1” and “Org2” you would specify a name pattern of _rg_.
For an example of finding objects by name, see JAXRSearchByName.java in the directory <INSTALL>/registry/samples/search-name/src.
Go to the directory <INSTALL>/registry/samples/search-name.
Type the following command, specifying a string value:
asant run -Dname=string |
The program performs a case-insensitive search, returning all objects whose names contain the specified string. The program also displays the object’s classifications, external identifiers, external links, slots, and audit trail.