how to add users and roles to Team Area using Plain Java API ?
3 answers
Here is code to find process area (team/project) areas etc: https://rsjazz.wordpress.com/2012/12/09/analyzing-a-aroject-areas-members-and-roles-using-the-plain-java-client-libraries/
If you have the process area, here is the API to add a contributor:
processArea.addMember(contributorHandle)
https://rsjazz.wordpress.com has other posts that describe how to get to the contributor handle from the ID.
If you have the process area, here is the API to add a contributor:
processArea.addMember(contributorHandle)
https://rsjazz.wordpress.com has other posts that describe how to get to the contributor handle from the ID.
Thanks Ralph, I had already visited the link and its been a great help. I could successfully add the contributor from a CSV file but I am facing issue in adding roles to contributors. I want to assign the roles to contributor from the CSV file itself. CSV file has details of team area(where contributor has to be added), contributor list and the role corresponding to each contributor. I can successfully add roles from the available role list in projectarea (with help of snippet3 example) but my need is to add the role from CSV file. I have written the code but don't understand where am I missing. Copying the relevant code. Please help.
IProcessItemService service= (IProcessItemService) teamRepository.getClientLibrary(IProcessItemService.class);
IClientProcess clientProcess = service.getClientProcess(area, null);
IRole[] availableRoles = clientProcess.getRoles(area, null);
IRole return_role2 = (IRole)null;
String role1;
for (int k = 0; k < availableRoles.length; k++) {
IRole return_role = (IRole)availableRoles[k];
role1 = return_role.getId();
if(role1.equalsIgnoreCase(member_roles))
{
return_role2 = return_role;
}
}
IContributor user = teamRepository.contributorManager().fetchContributorByUserId(members,monitor);
IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy)service.getWorkingCopyManager().createPrivateWorkingCopy(teamArea);
areaWc.getTeam().addContributorsSettingRoleCast(
new IContributor[] {user},
new IRole[] {return_role2});
areaWc.save(monitor);
Comments
Probably I would be able to resolve my problem if I come to know how can I store arrayList into IRole . In this line, IRole[] availableRoles = clientProcess.getRoles(area,null); I want to have values read from csv file and not from processarea. Any syntax help will be great .
public static void main(String[] args) throws IOException {
TeamPlatform.startup();
List <String> teamAreaList = new ArrayList<String>();
List <String> membersList = new ArrayList<String>();
List <String> roleList = new ArrayList<String>();
IRole return_role3 = null;
try {
String filename = args[7];
BufferedReader CSVFileReader = new BufferedReader(new FileReader(filename));
String row ="";
StringTokenizer st = null;
while((row = CSVFileReader.readLine()) != null )
{
rowNumber++;
st = new StringTokenizer(row,",");
while (st.hasMoreTokens()) {
teamAreaList.add(st.nextToken());
membersList.add(st.nextToken());
roleList.add(st.nextToken());
}
}
for (int i=1; i<rowNumber; i++)
{
projectAreaName = projectAreaList.get(i);
teamAreaName = teamAreaList.get(i);
members = membersList.get(i);
member_roles = roleList.get(i);
IClientProcess clientProcess = service.getClientProcess(area, null);
IRole[] availableRoles = clientProcess.getRoles(area,null);
for (int m = 1; i < availableRoles.length; m++) {
IRole return_role = (IRole)availableRoles[m];
role1 = return_role.getId();
if(role1.equalsIgnoreCase(member_roles))
{
return_role3 = return_role;
}
}
IContributor user = teamRepository.contributorManager().fetchContributorByUserId(members,monitor);
IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy)service.getWorkingCopyManager().createPrivateWorkingCopy(teamArea);
areaWc.getTeam().addContributorsSettingRoleCast(
new IContributor[] {user},
new IRole[] {return_role3});
areaWc.save(monitor);
}
Comments
Kaushambi Singh
Jun 10 '13, 7:05 a.m.