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
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.
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.
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).
If you closely look into my example, it shows the code below. So you have to iterate the roles, get an IRole type element by some criteria, have a new IRole[] variable and add the role. You can also use an ArrayList<IRole> and then get the array from that. You need to pass an IRole[] as far as I can tell.
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 vote
I found this API call:
/** * Appends the given roles to the collection of roles assigned to the given * contributor. ** If any of the given roles are already assigned to the given * contributor, those roles will be ignored. Callers wishing to reorder * role assignments should call setRoleAssignments(...) instead. *
* Roles passed into this method should be a subset of available roles * for this process area retrieved by calling either: * com.ibm.team.process.service.IServerProcess#getRoles(IProcessArea) or * com.ibm.team.process.client.IClientProcess#getRoles(IProcessArea, * IProgressMonitor) * * @param contributor the contributor whose roles to assign * @param roles the roles to append */ public void addRoleAssignments(IContributorHandle contributor, IRole[] roles);
1 vote
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.
The code above assumes you have the roles specified in the process specification.
If you have user/role mappings in the CSV file you would have to
- Read the CSV file, user team, roles
-
Find the Project Area, team area, user(contributor), add the user if he is not already member, get the users roles, map the roes to the desired ones. If there are roles missing, read the available roles from the process area and add the role with the desired ID or name to the process area for the specific user.
1 vote
Ralph, nice find.. (the addRoleAssignments).. I need that..
Sam in the post above it appears to be an interface of the IProcessArea class.
This should be common to client and server API See https://rsjazz.wordpress.com/2013/09/18/deploying-templates-and-creating-projects-using-the-plain-java-clients-library/ for the client libraries in method
addUsersAndRoles
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());// IProjectArea wArea = (IProjectArea)service.getMutableCopy(area); IContributor member = teamRepository.loggedInContributor(); IRole role = getRole(area, "ScrumMaster", monitor); area.addAdministrator(member); area.addMember(member);
that method is in com.ibm.team.process.common.IProcessArea.
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.
Just the Plain Java Javadoc, is really very limited.
thanks.. I do the api search quite often, and can view the source all the time.
turns out I can shortcut setting the project roles by using the existing project as a project template for the new projects..
Ralph, thanks for pushing me..
I of course have looked at all the source for all the plugins I have done and system extensions and improvements.. nice to have it available for the plain java apps too.
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.
setRoleAssignments works fine, however.
1 vote
Comments
A B
Feb 06 '13, 1:01 p.m.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:
-------------------------------------------------------------------------------------------------------------------------------