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(); } |
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. Comments
Berthold Kröger
commented Oct 17 '14, 9:02 a.m.
Hi Sam, thank you for your quick answer. But there is no save() method for IProcessArea!
|
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()".