Programatically assign roles to RTC Users -- Using Plain Java
Hi, We are trying to programatically assign roles to RTC users(we are on 4.0.0.1) in a Project Area. We got some information at https://jazz.net/forum/questions/33551/teams-role-api but are not able to do much with it. Any code snippets, examples, pointers would be very usefull. Regards, A |
Accepted answer
Ralph Schoon (63.4k●3●36●46)
| answered Feb 05 '13, 8:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This depends on how you want to do that. An example using the Plain Java Client Libraries to get the data can be found here: http://rsjazz.wordpress.com/2012/12/09/analyzing-a-aroject-areas-members-and-roles-using-the-plain-java-client-libraries/
Scanning the post https://jazz.net/forum/questions/33551/teams-role-api seems to indicate that some (the first part) is server code, whereas the last parts is mostly client API. although these are typically very similar, there are differences for example the names of client Libraries and Server Services are slightly different and the mechanisms to get them too. I have not tried to set a user role, but the blog post might give you some hints about the API. Another hint would be that modifying a lot of the artifacts requires to get a WorkingcopyManager and a working copy, then modify the data in the working copy and save the workingcopy using the manager. A B selected this answer as the correct answer
Comments
Thanks a lot for sharing the information Ralph, it was helpful.I am now trying to use setRoleAssignments to set the roles at project level. However, I am not able to able to figure out how to give value for its second argument.
setRoleAssignments(IContributorHandle arg0,IRole[] arg1)
Any more clues, hints or some reference documents…?(sorry if it is too naive).It seems to me that some kind of typecasting is required here but not able to figure it out till now (sigh.. that’s what happen when a DB guy works on java :P). :)
//Get Contributor Handle --- For POC trying to update roles of user who last modified the PA
IContributorHandle handle2 = processArea.getModifiedBy();
IContributor contributor = (IContributor) teamRepository.itemManager().fetchCompleteItem(handle2, IItemManager.REFRESH, null);
//Get Working Copy
IContributor contributorWorkingCopy = (IContributor) contributor.getWorkingCopy();
//Print Contributor Name
System.out.print(": " + contributor.getUserId() + "\t"+ contributor.getName() + "\t" + contributor.getEmailAddress()+ "\t");
//Get Roles
IRole[] roles2 = null;
processArea.setRoleAssignments(handle2, roles2);
teamRepository.contributorManager().saveContributor(contributorWorkingCopy, null);
1
I would suggest to set up the dev client according to https://jazz.net/library/article/1000 . Then make your project a Plugin Project. Then you have the PDE and can search for examples for the call in the RTC Eclipse Client (SDK).
IRole[] contributorRoles = process.getContributorRoles(contributor, processArea, null); for (int j = 0; j < contributorRoles.length; j++) { IRole role = (IRole) contributorRoles[j]; System.out.print(role.getId() + " "); } 1
Ralph Schoon
commented Feb 06 '13, 8:58 a.m.
| edited Feb 06 '13, 8:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
/** * Appends the given roles to the collection of roles assigned to the given * contributor. * Thanks a lot for sharing all these details Ralph..!! In our case we will have user role names in a CSV file. So seems like for us steps will be: 1. Read data from CSV into a variable. 2. Create a role type element and assing the value from step 1 to it. 3. create a IRole[] Variable and add the role. I work to implement it. Thanks again for sharing the insight. 1
Ralph Schoon
commented Feb 06 '13, 11:02 a.m.
| edited Feb 06 '13, 11:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The code above assumes you have the roles specified in the process specification.
sam detweiler
commented Dec 17 '13, 5:42 p.m.
Ralph, nice find.. (the addRoleAssignments).. I need that..
but its unclear on what class/service that api is available from.
not from processitemservice or IClientProcess
any helpful pointers?
Sam in the post above it appears to be an interface of the IProcessArea class.
addUsersAndRoles
sam detweiler
commented Dec 18 '13, 8:40 a.m.
hm.. your code uses the IProjectArea area = (IProjectArea) service.getMutableCopy(area); System.out.println("Trying to add members with roles: " + "ScrumMaster" + " to Project Area" + area.getName());
area.addRoleAssignments(member, new IRole[] { role });
I don't see that method on projectarea. (3.0.1)
that method is in com.ibm.team.process.common.IProcessArea.
but ONLY in 4.x and above. not there in 3.x
RolePersistence.getPersistedRoleData(teamdata,contributor)
and
RolePersistence.setPersistedRoleData(teamdata,contributor,(String roles);
and should work on 4.x
work
Sam, I would really, really, really, really, really like to suggest to follow http://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ and the related articles to set up the plain java client libraries with a compatible SDK. This makes searching for API so much easier. For example, you could search for where IRole or IRole2 is used in the SDK and easily find the service and code you want.
sam detweiler
commented Dec 18 '13, 11:02 a.m.
thanks.. I do the api search quite often, and can view the source all the time.
but you cannot find what isn't there.. addRoleAssignments() is not in 3.x
another example
set the project available roles, I can get them, but in 3.x (at least) there is no set method.
search will not find it either!..
sam detweiler
commented Dec 18 '13, 12:07 p.m.
turns out I can shortcut setting the project roles by using the existing project as a project template for the new projects..
sam detweiler
commented Dec 18 '13, 9:02 p.m.
Ralph, thanks for pushing me..
1
Sterling Bates
commented Dec 27 '13, 6:25 p.m.
As a heads up, I've found "addRoleAssignments" to be unreliable, and actually remove random roles while also not setting the new one. For example, when calling it with a new "projectmanager" role for my own user, the first time it removed my "Administrator" role assignment, and the second time it removed "team-member". Neither time added the new role.
showing 5 of 15
show 10 more comments
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
Created some dirty code to do POC on roles of updation. Created a code to Add roles of an administrative user to the user who last updated the PA. However, following line gives an error:
processArea.addRoleAssignments(handle, contributorRoles);
com.ibm.team.repository.common.internal.ImmutablePropertyException. It seems that i need to make a working copy of handle or we are doing some thing wrong over here?
Pasted below are the relevant code lines:
-------------------------------------------------------------------------------------------------------------------------------