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 > Program tasks


Create an entity using an asynchronous adapter

Use the create(DataObject) method with an asynchronous adapter to create an entity.


About this task

This type of call is same as the create person call, except that the call gets forwarded to an adapter that performs create operation asynchronously. This particular example shows how to create a PersonAccount entity, Person X under the container cn=users,dc=yourco,dc=com.

To create Person X under the container cn=users,dc=yourco,dc=com asynchronously, add this sample code to the application code and replace the variables with the actual values to use for this entity:

try {
    //create root dataobject from virtual member manager Service.
    DataObject root = service.createRootDataObject();
    DataObject personAccount = SDOHelper.createEntityDataObject(root, null, DO_PERSON_ACCOUNT);
    personAccount.set("uid", "personx");
    personAccount.set("cn", "Person X");
    personAccount.set("sn", "PersonXLastName");

    DataObject contexts = root.createDataObject(DO_CONTEXTS);
    contexts.set(PROP_KEY, VALUE_CONTEXT_REALM_KEY);
    contexts.set(PROP_VALUE, "realmA");
    root = service.create(root);

    // Check the response for ResponseControl dataobject
    // for incomplete async operation, we should receive a ticket.
    String ticket = checkResponse(root);

    if (ticket != null) {
        // build the input DataGraph with RequestControl to check the status
        root = service.createRootDataObject();
        DataObject reqCtrl = SDOHelper.createControlDataObject(root, null, DO_REQUEST_CONTROL);
        reqCtrl.setString(PROP_TICKET, ticket);
        // wait for the completion of the async operation
        DataObject retRoot = service.get(root);
        while (checkResponse(retRoot) != null) {
            Thread.sleep(200);
            retRoot = service.get(root);
        }
    }

catch(WIMException e) {
    e.printStackTrace();
}

// returns ticket if the operation is not complete private static String checkResponse(DataObject root) {
    DataObject rspCtrl = null;
    String ticket = null;
    List controls = root.getList(Service.DO_CONTROLS);
    if (controls != null) {
        for (int i = 0; i
< controls.size(); i++) {
            DataObject control = (DataObject)controls.get(i);
            String type = control.getType().getName();
            if (DO_RESPONSE_CONTROL.equals(type)) {
                rspCtrl = control;
                break;
            }
        }
    }
    if (rspCtrl != null) {
        boolean complete = rspCtrl.getBoolean(Service.PROP_COMPLETE);
        if (!complete) {
            ticket = rspCtrl.getString(Service.PROP_TICKET);
        }
    }
    return ticket;
}


Sample input and output data graphs

For this particular example the input data graph is:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
               xmlns:="//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/  ://www.w3.org/XML/1998/namespace"
               xmlns:sdo="commonj.sdo"
               xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:contexts>
<wim:key>realm
</wim:key>
<wim:value>realmA
</wim:value>
</contexts>
<wim:entities xsi:type="wim:PersonAccount">
<wim:uid>personx
</wim:uid>
<wim:cn>Person X
</wim:cn>
<wim:sn>PersonXLastName
</wim:sn>
</wim:entities>
</Root>
</sdo:datagraph> 

The resulting output data graph is:

<?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:controls xsi:type="wim:ResponseControl" complete="false"
                  ticket="AsyncLDAP1:1113940307424:-1278154994"/>
</wim:Root>
</sdo:datagraph> 

To check the status of the create operation, the input data graph for get() method is:

<?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:controls xsi:type="wim:RequestControl"
                               ticket="AsyncLDAP1:1113940307424:-1278154994"/>
</wim:Root>
</sdo:datagraph> 

If the create operation is not complete, the output data graph from get() method is same as the input data graph with the addition of a complete="false" statement:

<?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:controls xsi:type="wim:ResponseControl" complete="false"
                                      ticket="AsyncLDAP1:1113940307424:-1278154994"/>
</wim:Root>
</sdo:datagraph> 

If the create operation is complete, the resulting data graph for this example is:

<?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 repositoryId="AsyncLDAP1"
                      uniqueName="uid=personx,cn=users,dc=yourco,dc=com"/>
</wim:entities>
<wim:controls xsi:type="wim:ResponseControl" complete="true"/>
</wim:Root>
</sdo:datagraph> 

Parent topic: Program tasks



+

Search Tips   |   Advanced Search