Adding roles to users in team area in RTC

旧巷老猫 提交于 2020-01-03 02:30:07

问题


I need to add users ( users are already present in repository. I only need to add them.) and roles from a CSV file to team areas. Project area and Team Area already exists.I could successfully add users but not the roles from csv file.

The CSV file format is :

Project name,Team Area name,Members,roles
Project1,User_Role_TA,Alex,Team Member
Project2,TA2,David,Scrum Master

Below is the code for it. It successfully add the users and currently add roles to them from project area but I need to add roles to the users from CSV file. In the below code, If I can get roles from csv file in the line "IRole[] availableRoles = clientProcess.getRoles(area, null);" , I think it should resolve the issue. I am not getting any error but it doesn't add the roles.

     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");
        }

回答1:


Some of the API you are trying to use are private in RTC3.x

See this thread for different options (a bit similar to your code):

ProjectAreaWorkingCopy workingCopy = (ProjectAreaWorkingCopy)manager.getWorkingCopy(project);

this class extends to ProcessAreaWorkingCopy

public class ProjectAreaWorkingCopy extends ProcessAreaWorkingCopy implements IProjectAreaWorkingCopy

In ProcessAreaWorkingCopy setRoleCast retrieves the team and sets the role.

One can set the role at the team level via

team.setRoleCast(contributor, roleCast);
# or
projWc.getTeam().addContributorsSettingRoleCast(new IContributor[] {contributor}, roles);

The OP Kaushambi Suyal reports:

Created a method as mentioned in the thread with few changes and it worked.
Also we need to pass the process area here and not the project area, because I am trying to add roles to users in team area and not project area.



来源:https://stackoverflow.com/questions/17336621/adding-roles-to-users-in-team-area-in-rtc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!