Hi,
I found this code online. This does the required operation:
private void storeIterationVals(MigrationDetailsBean migDetailsBean, RTCServerConfig rtcServerConfig,
Object srcValue, IProgressMonitor monitor) throws TeamRepositoryException {
PathHelper ph = new PathHelper(rtcServerConfig.getSrcRepo(), monitor);
ph.calculateIterationPath((IterationHandle) srcValue);
String paths = "IDPath: [" + ph.toIDPathString() + "] NamePath: (" + ph.toNamePathString() + ")";
logger.info("Path to Iteration : " + ph.toIDPathString());
DevelopmentLineHelper devLineUtil = new DevelopmentLineHelper(rtcServerConfig.getSrcRepo(), monitor);
String iterationPath = ph.toNamePathString();
IProjectAreaHandle targetPAHandle = migDetailsBean.getTargetProjArea().getProjectArea();
List path = Arrays.asList(iterationPath.split("/"));
// map by ID
IIteration found = devLineUtil.findIteration(targetPAHandle, path, DevelopmentLineHelper.BYID);
if (found == null) {
found = devLineUtil.findIteration(targetPAHandle, path, DevelopmentLineHelper.BYNAME);
}
// IIterationHandle found =
// devLineUtil.fetchIterations(migDetailsBean.getTargetProjArea(), repo,
// monitor, iterationPath);
migDetailsBean.getTargetWI().setValue(migDetailsBean.getTargetAttribute(), found);
}
public IIteration findIteration(IProjectAreaHandle iProjectAreaHandle,
List<String> path, Comparemode comparemode) throws TeamRepositoryException {
fAuditableClient = (IAuditableClient) fTeamRepository
.getClientLibrary(IAuditableClient.class);
IIteration foundIteration = null;
IProjectArea projectArea = (IProjectArea) fTeamRepository.itemManager()
.fetchCompleteItem(iProjectAreaHandle, IItemManager.REFRESH,
fMonitor);
IDevelopmentLine developmentLine = findDevelopmentLine(projectArea,
path, comparemode);
if (developmentLine != null) {
foundIteration = findIteration(developmentLine.getIterations(),
path, 1, comparemode);
}
return foundIteration;
}
public IDevelopmentLine findDevelopmentLine(IProjectArea projectArea,
List<String> path, Comparemode comparemode) throws TeamRepositoryException {
int level = 0;
String fookFor = path.get(level);
IDevelopmentLineHandle[] developmentLineHandles = projectArea
.getDevelopmentLines();
for (IDevelopmentLineHandle developmentLineHandle : developmentLineHandles) {
IDevelopmentLine developmentLine = fAuditableClient
.resolveAuditable(developmentLineHandle,
ItemProfile.DEVELOPMENT_LINE_DEFAULT, fMonitor);
String compare = "";
switch(comparemode){
case BYID:
compare = developmentLine.getId();
break;
case BYNAME:
compare = developmentLine.getName();
break;
case BYLABEL:
compare = developmentLine.getLabel();
break;
}
if (fookFor.equals(compare)) {
return developmentLine;
}
}
return null;
}