on 08-17-2007 3:32 PM
Hi,
I would like to achieve a bit of programming that allows me to add a user to a group rather than straight to a role.
Has anyone been able to do this before or can anyone help.
I would gratefully appreciate it and will reward points.
Thanks
Kai
Solved
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kai,
its pretty simple. Try the following code:
I hope you have your user object whom you want to add to the group. I am just creating a user object for showing it - then obtaining the group also for simplicity. You would know better how would you find out the user object & the group object.
IUserFactory userFact = UMFactory.getUserFactory();
IGroupFactory groupFact = UMFactory.getGroupFactory();
try {
//obtain the user object
IUser user = userFact.getUserByLogonID("YOUR USER ID");
//get the unique id of the user
String userUniqueId = user.getUniqueID();
//obtain the group object
IGroup group = groupFact.getGroupByUniqueName("GROUP NAME");
//get the group unique id
String groupUniqueId = group.getUniqueID();
//assign the user to the group via GroupFactory
groupFact.addUserToGroup(userUniqueId, groupUniqueId);
} catch (UMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
});
And you are done!!!
Regards,
Shubhadip
Message was edited by:
Shubhadip Ghosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Kai Chalker
try this
IGroup getSingleGroup(String searchStr, boolean fuzzy) throws UMException {
IGroupFactory gFact = UMFactory.getGroupFactory();
IGroupSearchFilter gsf = gFact.getGroupSearchFilter();
if (fuzzy) {
gsf.setDisplayName("" + searchStr + "",
ISearchAttribute.LIKE_OPERATOR,false);
} else {
gsf.setDisplayName(searchStr,
ISearchAttribute.EQUALS_OPERATOR,false);
}
ISearchResult sr = gFact.searchGroups(gsf);
if (sr.size() == 0)
throw new UMException("Role: " + searchStr + " not found");
if (sr.size() == 1)
return gFact.getGroup((String) sr.next());
else
throw new UMException("Group: "+ searchStr +
" not unique (found "+ sr.size()+ " matches)");
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
UME API
They are pretty simple API's
Refer:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.