How can i assign multiple process roles to a user in a team area in RTC using plain java api?
Hello,
I need help in adding a user and assigning/adding him/her with multiple process roles in a team area. I have an array where i will be getting the process roles that i need to assign to the user.
static String role[] = new String[] {"Product Owner","User"};
I'm using the code below that i found here in jazz. It's working but the only process role that is being assigned is the last process role in the array. I think it's because of the new keyword for the IContributor and IRole in addContributorsSettingRoleCast, it just overwrites the current process role of the added user everytime it loops.
if (teamArea.getName().equals(teamAreaName)) {
System.out.println("Adding user to " + teamArea.getName() + " team area");
IProcessItemService service = (IProcessItemService) teamRepository.getClientLibrary(IProcessItemService.class);
IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy) service.getWorkingCopyManager().createPrivateWorkingCopy(teamArea);
IContributor contributor = teamRepository.contributorManager().fetchContributorByUserId(memberId, null);
areaWc.getTeam().addContributors(new IContributor[] {contributor});
for (int i = 0; i < role.length; i++) {
IRole roles = getRole(teamArea, role[i]);
areaWc.getTeam().addContributorsSettingRoleCast(new IContributor[] {contributor}, new IRole[] {roles});
}
System.out.println("Added " + contributor.getName());
areaWc.save(myProgressMonitor);
}
public static IRole getRole(IProcessArea processArea, String processRole) throws TeamRepositoryException {
IProcessItemService service =(IProcessItemService) teamRepository.getClientLibrary(IProcessItemService.class);
IClientProcess clientProcess = service.getClientProcess(processArea, null);
IRole[] availableRoles = clientProcess.getRoles(processArea, null);
for (int i = 0; i < availableRoles.length; i++) {
if (availableRoles[i].getId().equals(processRole)) {
return availableRoles[i];
}
}
Can addContributorsSettingRoleCast be used in adding multiple process roles? I tried using it with an ArrayList but there is an error with that. Can i use something else aside from addContributorsSettingRoleCast to add multiple process roles?
I need help in adding a user and assigning/adding him/her with multiple process roles in a team area. I have an array where i will be getting the process roles that i need to assign to the user.
static String role[] = new String[] {"Product Owner","User"};
I'm using the code below that i found here in jazz. It's working but the only process role that is being assigned is the last process role in the array. I think it's because of the new keyword for the IContributor and IRole in addContributorsSettingRoleCast, it just overwrites the current process role of the added user everytime it loops.
if (teamArea.getName().equals(teamAreaName)) {
System.out.println("Adding user to " + teamArea.getName() + " team area");
IProcessItemService service = (IProcessItemService) teamRepository.getClientLibrary(IProcessItemService.class);
IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy) service.getWorkingCopyManager().createPrivateWorkingCopy(teamArea);
IContributor contributor = teamRepository.contributorManager().fetchContributorByUserId(memberId, null);
areaWc.getTeam().addContributors(new IContributor[] {contributor});
for (int i = 0; i < role.length; i++) {
IRole roles = getRole(teamArea, role[i]);
areaWc.getTeam().addContributorsSettingRoleCast(new IContributor[] {contributor}, new IRole[] {roles});
}
System.out.println("Added " + contributor.getName());
areaWc.save(myProgressMonitor);
}
public static IRole getRole(IProcessArea processArea, String processRole) throws TeamRepositoryException {
IProcessItemService service =(IProcessItemService) teamRepository.getClientLibrary(IProcessItemService.class);
IClientProcess clientProcess = service.getClientProcess(processArea, null);
IRole[] availableRoles = clientProcess.getRoles(processArea, null);
for (int i = 0; i < availableRoles.length; i++) {
if (availableRoles[i].getId().equals(processRole)) {
return availableRoles[i];
}
}
Can addContributorsSettingRoleCast be used in adding multiple process roles? I tried using it with an ArrayList but there is an error with that. Can i use something else aside from addContributorsSettingRoleCast to add multiple process roles?
One answer
Please see the code in https://rsjazz.wordpress.com/2013/09/18/deploying-templates-and-creating-projects-using-the-plain-java-clients-library/ It should work with multiple roles as well.
Comments
Hi Ralph,
Thank you for this but i think this is adding multiple roles in a member of a project area. addRoleAssignments doesn't appear as an option for the team area. How will i make IRole to accept multiple roles? Is it possible?
ITeamArea has it too.
ITeamArea tArea=null; tArea.addRoleAssignments(contributor, roles)
IRole is the interface for one role.
You want to study https://rsjazz.wordpress.com/2013/02/28/setting-up-rational-team-concert-for-api-development/ and https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ thoroughly to understand what to do to set up your environment to be able to use content assist and to browse the API and the JavaDoc.