It's all about the answers!

Ask a question

Error in adding existing child of a team area to another team area using plain Java API


Kaushambi Singh (371310079) | asked Aug 14 '13, 5:08 p.m.
retagged Aug 15 '13, 10:14 a.m. by Ralph Earle (25739)
 I am getting error while adding existing child of one team area to another team area using plain java API. Adding similar child in different Team areas of a project area is allowed in RTC UI so this should be possible using API too.The code creates the team hierarchy the first time it runs but it throws error if I want to have same child in some other team area. The error is thrown at below line of the code : projectArea.getTeamAreaHierarchy().addChild(rootTeamAreaHandle, childTeamAreaHandle);
Error: " Exception in thread "main" com.ibm.team.process.common.TeamAreaHierarchyException: Child team area is already part of this team area hierarchy "
My relevant code :

  public void createTeamArea(ITeamRepository repo, String projectName, String rootTeamAreaName, String childTeamAreaName, String grandchildTeamAreaName,String teamAdmin, IProgressMonitor monitor) throws TeamRepositoryException {
                 
        IProcessItemService processItemService= (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
       
        ITeamAreaHandle rootTeamAreaHandle;
        ITeamAreaHandle childTeamAreaHandle;
        ITeamAreaHandle grandchildTeamAreaHandle;
        IProjectArea projectArea = getProjectAreaByName(projectName, monitor);
        
List<ITeamAreaHandle> teamlist = new ArrayList<ITeamAreaHandle>(); 
teamlist = projectArea.getTeamAreas();
ITeamAreaHandle rootTAHandle = findTeamAreaByName(teamRepository,teamlist, rootTeamAreaName, monitor);
if(!(rootTAHandle == null)){
rootTeamAreaHandle = (ITeamArea)repo.itemManager().fetchCompleteItem((ITeamAreaHandle)rootTAHandle, IItemManager.DEFAULT, monitor);
}
else {
   rootTeamAreaHandle = createTeamArea(repo,  projectArea, rootTeamAreaName, teamAdmin);
   
}
if (!childTeamAreaName.equals("NULL"))
{
ITeamAreaHandle childTAHandle = findTeamAreaByName(teamRepository,teamlist, childTeamAreaName, monitor);
if(!(childTAHandle == null)){
childTeamAreaHandle = (ITeamArea)repo.itemManager().fetchCompleteItem((ITeamAreaHandle)childTAHandle, IItemManager.DEFAULT, monitor);
}
else {
   childTeamAreaHandle = createTeamArea(repo,  projectArea, childTeamAreaName,teamAdmin);
}
       
ITeamAreaHandle grandchildTAHandle = findTeamAreaByName(teamRepository,teamlist, grandchildTeamAreaName, monitor);
if(!(grandchildTAHandle == null)){
grandchildTeamAreaHandle = (ITeamArea)repo.itemManager().fetchCompleteItem((ITeamAreaHandle)grandchildTAHandle, IItemManager.DEFAULT, monitor);
}
else {
   grandchildTeamAreaHandle = createTeamArea(repo,  projectArea, grandchildTeamAreaName,teamAdmin);
}
if (!(projectArea.getTeamAreaHierarchy().getParent(childTAHandle)== rootTAHandle))
{
projectArea = (IProjectArea) projectArea.getWorkingCopy();
projectArea.getTeamAreaHierarchy().addChild(rootTeamAreaHandle, childTeamAreaHandle);
projectArea.getTeamAreaHierarchy().addChild(childTeamAreaHandle, grandchildTeamAreaHandle);
}
processItemService.save(new IProcessItem[] {projectArea} , monitor);
Method  findTeamAreaByName () :
public static ITeamAreaHandle findTeamAreaByName(ITeamRepository teamRepository, List<ITeamAreaHandle> teamAreaHandleList, String teamAreaID, IProgressMonitor monitor) throws TeamRepositoryException{
for(ITeamAreaHandle teamAreaHandle : teamAreaHandleList){
ITeamArea teamArea = (ITeamArea)teamRepository.itemManager().fetchCompleteItem(teamAreaHandle,ItemManager.DEFAULT,monitor); 
if(teamAreaID.equals(teamArea.getName())){
return teamAreaHandle;
}
}
return null;
}

One answer



permanent link
David Murray (11612) | answered Aug 14 '13, 5:49 p.m.
JAZZ DEVELOPER
edited Aug 14 '13, 5:55 p.m.
 The error "Child team area is already part of this team area hierarchy" is thrown when any team area in the hierarchy is a parent of the team being added anyplace in the hierarchy.

You should be able to address this by using method com.ibm.team.process.internal.common.util.TeamAreaHierarchy::reparent(ITeamAreaHandle newParent, ITeamAreaHandle child) instead of addChild() when the team area already has a parent.

The code in the RTC IDE that implements drag-and-drop of team areas to move calls promoteToRoot() when the target is an instance of IProjectArea and invokes reparent() otherwise.

Your answer


Register or to post your answer.