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

How to remove an administrator from a project area programmatically

Hi, I'm working on an application that manages users in project and team areas. I use following code to remove a normal member from a project area:
            IContributor user = fetchUser(repository, userId, false);
            if (user != null) {
                IContributorHandle userHandle = (IContributorHandle) user.getItemHandle();
                // Zugriff auf die Project-Area
                IAuditableCommon auditableService = getAuditableCommon(repository);
                IProjectAreaHandle projectHandle = getProjectArea(auditableService, projectAreaName);
                if (projectHandle != null && projectHandle.isAuditable()) {
                    IProjectArea projectArea = (IProjectArea) repository.itemManager().
                            fetchCompleteItem(projectHandle, IItemManager.REFRESH, monitor);
                    if (projectArea != null && !projectArea.isArchived()) {
                        // Ist der User ein Member in dieser Project-Area?
                        if (projectArea.hasMember(userHandle)) {
                            logger.fine("User "+userId+" found in Project area "+projectAreaName+"!");
                            ProjectAreaWorkingCopy area = new ProjectAreaWorkingCopy(projectArea);
                            area.removeMembers(new IContributor[] {user});
                            area.save(monitor);
                            // Kopie freigeben
                            area.dispose();
                        }

But how can I remove an adminstrator from a project area. There is no method "removeAdministrator()" for ProjectAreaWorkingCopy. The removeAdministrator() is only defined for the type IProcessArea. But if I try to do it this way:
                        if (projectArea.hasAdministrator(userHandle)) {
                            ProjectAreaWorkingCopy area = new ProjectAreaWorkingCopy(projectArea);
                            IProcessArea processArea = area.getUnderlyingProcessArea();
                            processArea.addAdministrator(userHandle);
                            area.save(monitor);
                            area.dispose();
                        }
I'll get a com.ibm.team.repository.common.internal.ImmutablePropertyException. I don't understand what I did wrong!

0 votes

Comments

Sorry there was a copy/paste error: of course the method was
processArea.removeAdministrator(userHandle) instead of
"addAdministrator()".



2 answers

Permanent link
After some unsuccessful attempts I finally found it: you must remove the contributor from the list of administrators in the project area working copy, e.g.

                        if (projectArea.hasAdministrator(contributorHandle)) {
                            ProjectAreaWorkingCopy projectAreaWC = new ProjectAreaWorkingCopy(projectArea);
                            IContributorListWorkingCopy adminList = projectAreaWC.getAdministrators();
                            adminList.removeContributors(new IContributor[] { contributor });
                            adminList.setDirty(true);
                            projectAreaWC.save(monitor);
                            projectAreaWC.dispose();
                        }

1 vote


Permanent link

            IProcessArea p;
            p=(IProcessArea) p.getWorkingCopy();
            p..removeAdministrator(userHandle);
           p. newitemlist.add(p);  // see below
etc

fixed
private static ITeamRepository Server = null;
private static IProcessItemService processItemClient = null;
processItemClient = (IProcessItemService) server.getClientLibrary(IProcessItemService.class);
                ArrayList<IProcessItem> newitemlist = new ArrayList<IProcessItem>();
                // allocate space for the array
                IProcessItem[] ilist = new IProcessItem[newitemlist.size()];
                // build the arrary
                ilist = newitemlist.toArray(ilist);
                // call save for the list of changed process items
                processItemClient.save(ilist, null);

processItemClient.save() takes an array of item handles. in my utility I do not know how many items will be changed in advance.. so I create a list, save the handles in the list, then turn that list into an array.

0 votes

Comments

Hi Sam, thank you for your quick answer. But there is no save() method for IProcessArea!

Regards,
Berthold

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

Question asked: Oct 17 '14, 7:45 a.m.

Question was seen: 3,708 times

Last updated: Nov 19 '14, 9:00 a.m.

Confirmation Cancel Confirm