Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How can I modify roles of an already existing user using Java API

 Is it possible to modify roles of user who is already present in team area using Java API. How? I am successful in adding roles to users but in case user already has roles , how can I modify (refresh) them using API ?

0 votes



One answer

Permanent link
Oh oh,  I know this.   What you have to do is get the user's current role(s), filter out the 'default' and append the new role[s].

The below method came from Ralph's 'dumpContributor' example which I shamelessly have made use of:
	private static IRole[] getProcessAreaRoles(ITeamRepository teamRepository,
	            IProcessArea processArea, IContributorHandle handle)
throws TeamRepositoryException {
IContributor contributor = (IContributor) teamRepository.itemManager()
.fetchCompleteItem(handle, IItemManager.DEFAULT, null);
// System.out.print(": " + contributor.getUserId() + "\t"
// + contributor.getName() + "\t" + contributor.getEmailAddress()+ "\t");
IProcessItemService processService = (IProcessItemService) teamRepository
.getClientLibrary(IProcessItemService.class);
IClientProcess process = processService.getClientProcess(processArea,
null);
IRole[] contributorRoles = process.getContributorRoles(contributor,
processArea, null);
return contributorRoles;
// for (int j = 0; j < contributorRoles.length; j++) {
// IRole role = (IRole) contributorRoles[j];
// System.out.print(role.getId() + " ");
// }
// System.out.println();
}

private IRole[] appendRoles(IRole[] newRoles,IRole[] oldRoles) {
if (oldRoles == null)
return newRoles;

IRole[] roleList=new IRole[oldRoles.length];
int i=0,n=1;
roleList[0]=newRoles[0]; // this one should be a singular list
while (i < oldRoles.length) {
if (!"default".equals(oldRoles[i].getId()) ) {
roleList[n]=oldRoles[i];
n++;
}
i++;
}
return roleList;
}

In the part of the Class that uses the above that actually adds/updates the Contributor:

contributorRole[0] = findRoleByName(teamRepository, (IProcessArea)project, projectRole);
if (contributorRole[0] != null) {
if (userInRepos) {
allRoles=getProcessAreaRoles(teamRepository,project,newContributor);
}
if (allRoles != null) {
contributorRole=appendRoles(contributorRole,allRoles);
}
projectAreaWorkingCopy.setRoleCast(newContributor, contributorRole);
 

0 votes

Comments

Thanks Kevin. 

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,939

Question asked: Jul 11 '13, 8:24 a.m.

Question was seen: 4,836 times

Last updated: Jul 12 '13, 6:10 a.m.

Confirmation Cancel Confirm