Assigning entities to a group
Use the update(DataObject) method and GroupMemberControl to assign one or more entities to a group.
About this task
This example shows how to assign SalesPerson1 and SalesPerson2
to the group, Managers. In this example, SalesPerson1 and SalesPerson2
are passed using the members property of the Managers.
Note: These
calls are MODIFY_MODE_ASSIGN by default, that is, membership is not
being replaced but added to by the call.
To add SalesPerson1
and SalesPerson2 to Managers, add this sample code to you application
code and replace the variables with the actual values that
you want to use for this request:
DataObject root = SDOHelper.createRootDataObject();
DataObject entity = SDOHelper.createEntityDataObject(root, null, DO_GROUP);
entity.createDataObject(DO_IDENTIFIER).set(PROP_UNIQUE_NAME,
"cn=Managers,cn=groups,dc=yourco,dc=com");
DataObject member1 = SDOHelper.createDataObject(WIM_NS_URI, DO_ENTITY);
member1.createDataObject(DO_IDENTIFIER).setString(PROP_UNIQUE_NAME,
"uid=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com");
DataObject member2 = SDOHelper.createDataObject(WIM_NS_URI, DO_ENTITY);
member2.createDataObject(DO_IDENTIFIER).setString(PROP_UNIQUE_NAME,
"uid=SalesPerson2,ou=CA,o=Sales,cn=users,dc=yourco,dc=com");
entity.getList(DO_MEMBERS).add(member1);
entity.getList(DO_MEMBERS).add(member2);
root = service.update(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:identifier uniqueName="cn=Managers,cn=groups,dc=yourco,dc=com"/>
<wim:members>
<wim:identifier uniqueName="uid=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"/>
</wim:members>
<wim:members>
<wim:identifier uniqueId="a3f9e8a1-117a-4252-840f-6d0cb079a7fb"/>
</wim:members>
</wim:entities>
</wim:Root>
</sdo:datagraph>
The resulting output data graph for this example
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 externalId="6e45af37-bc3f-4260-af27-666e1ebdbda2"
externalName="cn=Managers,cn=groups,dc=yourco,dc=com"
repositoryId="LDAP1"
uniqueId="6e45af37-bc3f-4260-af27-666e1ebdbda2"
uniqueName="cn=Managers,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.