Assigning an entity to multiple groups
Use the update(DataObject) method and GroupMembershipControl to assign an entity to one or more groups.
About this task
This example shows how to assign SalesPerson1 to groups
Managers and Admins.
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 to groups Managers and Admins, add this sample code
to your 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_ENTITY);
entity.createDataObject(DO_IDENTIFIER).set(PROP_UNIQUE_ID,
"79184c75-15df-4995-8587-bb763a236dc8");
DataObject grp1 = SDOHelper.createDataObject(WIM_NS_URI, DO_GROUP);
grp1.createDataObject(DO_IDENTIFIER).setString(PROP_UNIQUE_NAME,
"cn=Admins,cn=groups,dc=yourco,dc=com");
DataObject grp2 = SDOHelper.createDataObject(WIM_NS_URI, DO_GROUP);
grp2.createDataObject(DO_IDENTIFIER).setString(PROP_UNIQUE_NAME,
"cn=Managers,cn=groups,dc=yourco,dc=com");
entity.getList(DO_GROUPS).add(grp1);
entity.getList(DO_GROUPS).add(grp2);
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:sdo="commonj.sdo"
xmlns:wim="http://www.ibm.com/websphere/wim">
<wim:Root>
<wim:entities>
<wim:identifier uniqueId="e7db8c0e-d2b3-43fe-be14-1475125606f4"/>
<wim:groups>
<wim:identifier uniqueName="cn=Admins,cn=groups,dc=yourco,dc=com"/>
</wim:groups>
<wim:groups>
<wim:identifier uniqueId="6e45af37-bc3f-4260-af27-666e1ebdbda2"/>
</wim:groups>
</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:PersonAccount">
<wim:identifier externalId="e7db8c0e-d2b3-43fe-be14-1475125606f4"
externalName="uid=SalesPerson1,ou=CA,o=Sales,cn=users,dc=yourco,dc=com"
repositoryId="LDAP1"
uniqueId="e7db8c0e-d2b3-43fe-be14-1475125606f4"
uniqueName="uid=SalesPerson1,ou=CA,o=Sales,cn=users,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.