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

how to add users and roles to Team Area using Plain Java API ?

How can we add list of users to Team Area using Java API ? Users already exists in the repository. It just that I need to add them in Team Area and assign roles.

0 votes

Comments
Please help with the answer.



3 answers

Permanent link
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.

0 votes


Permanent link
 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);

0 votes

Comments
Without knowing any symptoms of the difficulties, how am I supposed to help? The code you are looking for is mostly covered in Snippet3 that ships with the Plain Java Client Libraries download.

I am geting IIlegalArgumentException . In IRole return_role2, I am trying to assign roles which is mentioned in csv file after matching with available roles in project and then passing into argument of new IRole[] {return_role2});  if(role1.equalsIgnoreCase(member_roles)) {                 return_role2 = return_role ;} Is it the correct way of doing ?

How am I supposed to tell. The code is not complete. I would suggest to read http://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ and to follow the hints for debugging. When debugging, you should be able to tell which arguments you return. Also look at snippet3 and run it to see what should be returned.


Permanent link
 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);
               
               
            }


0 votes

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
× 3,980

Question asked: Jun 07 '13, 5:05 a.m.

Question was seen: 117 times

Last updated: Jun 24 '13, 6:02 a.m.

Confirmation Cancel Confirm