Creating a group with an initial member

Use the create(DataObject) method to create a group with an initial person assigned to that group.

About this task

Use the create method to create a group entity. This example shows how to create Group Admins and assign an existing person, Person Admin, to it. The Group Admins is created under “cn=groups,dc=yourco,dc=com”. The unique name of the parent is passed in from the parent property.
To create a group and assign an existing person to that group add the following sample code to your application code and replace the variables with the actual values that you want to use for this entity:
DataObject root = service.createRootDataObject();
	DataObject entity = SDOHelper.createEntityDataObject(root, null, DO_GROUP);
	entity.set("cn", "Admins");
	entity.createDataObject(DO_MEMBERS).createDataObject(DO_IDENTIFIER).
  setString(PROP_UNIQUE_NAME, "uid=Admin,cn=users,dc=yourco,dc=com");
	root = service.create(root);

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="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:sdo="commonj.sdo" 
               xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:entities xsi:type="wim:Group">
      <wim:cn>Admins</wim:cn>
      <wim:members>
        <wim:identifier uniqueName="uid=Admin,cn=users,dc=yourco,dc=com"/>
      </wim:members>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>
The resulting output data graph is:
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:sdo="commonj.sdo" 
               xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:entities xsi:type="wim:Group">
      <wim:identifier externalName="cn=Admins,cn=groups,dc=yourco,dc=com" 
                      repositoryId="LDAP1"
                      uniqueId="73dc5d64-be44-4db0-9697-9a69056eb699"  
                      uniqueName="cn=Admins,cn=groups,dc=yourco,dc=com"/>
    </wim:entities>
  </wim:Root>
</sdo:datagraph>

For end-to-end sample code, see the topic, Sample code for working with users, groups, group members, and group memberships.

What to do next

To verify that your entry was created, you can perform a search on Group Admins and view its members.


Terms of use | Feedback

http://publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/com.ibm.websphere.wim.doc/creatingagroupandassigningaperson.html