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! |
2 answers
![]()
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(); } |
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.
Comments
Sorry there was a copy/paste error: of course the method was
processArea.removeAdministrator(userHandle) instead of
"addAdministrator()".