Express (Distributed operating systems), v8.0 > Secure applications and their environment > Authenticate users > Select a registry or repository > Manage realms in a federated repository > Virtual member manager > Develop with virtual member manager > Integrate virtual member manager into the application > Sample code


Sample code for search based on extended property value

Use the sample code snippet and data graph to perform a search based on the value of an extended property.

The following sample code snippet and data graph show how to use a search base to search for entities with the value of an extended property age as the search criteria.


Prerequisites

Ensure that we have read the information and completed the steps described in the topic, Program prerequisites, which also lists the valid syntax for property data types.

We must have entities with extended properties populated in different search bases. For sample code on how to create extended properties, see the following topics


Sample code

Add the following code snippet to the application code and replace the variables with the actual values to use.

private static void searchWithSearchBase()
{
    try
    {
        //Search Person B
        DataObject root = SDOHelper.createRootDataObject();
        DataObject searchCtrl = SDOHelper.createControlDataObject(root, null,
                SchemaConstants.DO_SEARCH_CONTROL);
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("uid");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("sn");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("cn");
        searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("age");
        /**
         * We can add search bases to the search as shown below:
         * o=defaultWIMFileBasedRealm for default file repository search

* or
 * dc=yourco,dc=com for the LDAP repository search.
         * If no search base is provided, the search runs across all the base entries configured.
         */
        searchCtrl.getList(SchemaConstants.PROP_SEARCH_BASES).add("o=defaultWIMFileBasedRealm");
        searchCtrl.setString(SchemaConstants.PROP_SEARCH_EXPRESSION,
                "@xsi:type='PersonAccount' and age > 2");
        root = service.search(root);
        System.out.println("Output data graph" +  printDO(root));
        printIdentifiers(root);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

We can validate the search results by verifying that the entities belong to the search base specified, such as o=defaultWIMFileBasedRealm for a default file repository search or dc=yourco,dc=com for the LDAP repository search.


Output data graphs

Output data graph for using a search base to search for entities based on the value of an extended property:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
    xmlns:sdo="commonj.sdo" xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:entities xsi:type="wim:PersonAccount">
<wim:identifier externalName="uid=personb,o=defaultWIMFileBasedRealm"
          repositoryId="InternalFileRepository"
          uniqueId="9e27cd3b-6300-4264-a4ac-768dd1092d11"
          uniqueName="uid=personb,o=defaultWIMFileBasedRealm"/>
<wim:uid>personb
</wim:uid>
<wim:cn>Person B
</wim:cn>
<wim:sn>PersonBLastName
</wim:sn>
</wim:entities>
</wim:Root>
</sdo:datagraph> 

Parent topic: Sample code



+

Search Tips   |   Advanced Search