我需要添加用戶(用戶已存在於存儲庫中,我只需要添加他們)以及從CSV文件到團隊區域的角色。項目區域和團隊區域已經存在。我可以成功添加用戶,但不能從csv文件中添加角色。向RTC團隊區域中的用戶添加角色
CSV文件格式是:
Project name,Team Area name,Members,roles
Project1,User_Role_TA,Alex,Team Member
Project2,TA2,David,Scrum Master
下面是它的代碼。它成功添加了用戶,並且目前爲他們添加了來自項目區域的角色,但我需要從CSV文件中爲用戶添加角色。在下面的代碼中,如果我可以從csv文件中的角色「IRole [] availableRoles = clientProcess.getRoles(area,null);」 ,我認爲它應該解決這個問題。我沒有收到任何錯誤,但沒有添加角色。
while((row = CSVFileReader.readLine()) != null)
{
rowNumber++;
st = new StringTokenizer(row,",");
while (st.hasMoreTokens()) {
projectAreaList.add(st.nextToken());
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);
URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));
IProjectArea projectArea = (IProjectArea) processClient.findProcessArea(uri, null, null);
if (projectArea == null)
{
System.out.println("Project Area not found");
}
if (!teamAreaName.equals("NULL")){
List <TeamAreaHandle> teamlist = projectArea.getTeamAreas();
ITeamAreaHandle newTAHandle = findTeamAreaByName(teamlist,teamAreaName,monitor);
if(newTAHandle == null) {
System.out.println("Team Area not found");
}
else {
ITeamArea TA = (ITeamArea)teamRepository.itemManager().fetchCompleteItem(newTAHandle,ItemManager.DEFAULT,monitor);
IRole role = getRole(projectArea);
IContributor user = teamRepository.contributorManager().fetchContributorByUserId(members,monitor);
/*role1 = getRole(area).getId();
if(role1.equalsIgnoreCase(member_roles))
{
user_role = getRole(area);
}*/
IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy)service.getWorkingCopyManager().createPrivateWorkingCopy(TA);
areaWc.getTeam().addContributorsSettingRoleCast(
new IContributor[] {user},
new IRole[] {role});
areaWc.save(monitor);
}
public static IRole getRole(IProcessArea area) throws TeamRepositoryException {
ITeamRepository repo = (ITeamRepository) area.getOrigin();
IProcessItemService service =(IProcessItemService) repo
.getClientLibrary(IProcessItemService.class);
IClientProcess clientProcess = service.getClientProcess(area, null);
IRole[] availableRoles = clientProcess.getRoles(area, null);
for (int i = 0; i < availableRoles.length; i++) {
return availableRoles[i];
}
throw new IllegalArgumentException("Couldn't find role");
}
您使用的是RTC3.x還是RTC4.x? – VonC
我正在使用RTC 3.0.1.3 –