Adding roles to users in team area in RTC
Asked Answered
rtc
E

1

1

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");
        }
Eteocles answered 27/6, 2013 at 7:2 Comment(2)
Are you using RTC3.x or RTC4.x ?Splendent
I am using RTC 3.0.1.3Eteocles
S
0

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.

Splendent answered 27/6, 2013 at 11:13 Comment(4)
Sorry for getting back late on this. My issue still stands there. I want to set roles from csv file as mentioned in question. I had seen this thread and your answer but still I am not able to resolve it. What I need is if someway I can cast the string member_roles to IRole, it would resolve the issue. Please help.Eteocles
@KaushambiSuyal Interesting. At this point, jazz.net is certainly the place where to seek that kind of information.Splendent
Finally I could add roles.Created a method as mentioned in the thread with few changes and it worked. Also would like to mention, 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.Eteocles
@KaushambiSuyal Excellent. I have added your conclusion to the answer for more visibility.Splendent

© 2022 - 2024 — McMap. All rights reserved.