create or delete iteration and timelines programatically
Accepted answer
Not sure if this will be of any use to you anymore, but here is a sample code of how you can do it:
Create Development lines:
IProcessItemService service= (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
projectArea = (IProjectArea) service.getMutableCopy(projectArea);
IDevelopmentLine developmentLine = (IDevelopmentLine) IDevelopmentLine.ITEM_TYPE.createItem();
developmentLine.setId("156");
developmentLine.setName("New Development Line");
developmentLine.setProjectArea(projectArea);
projectArea.addDevelopmentLine(developmentLine);
service.save(new IProcessItem[] { projectArea, developmentLine }, monitor);
Create Iterations:
IProcessItemService service= (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
IIteration newIteration = (IIteration) IIteration.ITEM_TYPE.createItem();
newIteration.setName("Ssdfecowsdfnd Iteration");
newIteration.setId("193");
IDevelopmentLine workingDevLine = (IDevelopmentLine) devLine.getWorkingCopy();
workingDevLine.addIteration((IIterationHandle) newIteration.getItemHandle());
newIteration.setDevelopmentLine(workingDevLine);
service.save(new IProcessItem[] { workingDevLine, newIteration }, monitor);
Create Development lines:
IProcessItemService service= (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
projectArea = (IProjectArea) service.getMutableCopy(projectArea);
IDevelopmentLine developmentLine = (IDevelopmentLine) IDevelopmentLine.ITEM_TYPE.createItem();
developmentLine.setId("156");
developmentLine.setName("New Development Line");
developmentLine.setProjectArea(projectArea);
projectArea.addDevelopmentLine(developmentLine);
service.save(new IProcessItem[] { projectArea, developmentLine }, monitor);
Create Iterations:
IProcessItemService service= (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
IIteration newIteration = (IIteration) IIteration.ITEM_TYPE.createItem();
newIteration.setName("Ssdfecowsdfnd Iteration");
newIteration.setId("193");
IDevelopmentLine workingDevLine = (IDevelopmentLine) devLine.getWorkingCopy();
workingDevLine.addIteration((IIterationHandle) newIteration.getItemHandle());
newIteration.setDevelopmentLine(workingDevLine);
service.save(new IProcessItem[] { workingDevLine, newIteration }, monitor);
9 other answers
Here is the method to create child iteration for an iteration:
IProcessItemService service = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
IDevelopmentLine workingDevLine = (IDevelopmentLine) createIterationDevLine.getWorkingCopy();
IIteration iterationCopy = (IIteration) newIteration.getWorkingCopy();
IIteration newSubIteration = (IIteration) IIteration.ITEM_TYPE.createItem();
newSubIteration.setName("Sub Iteration - 5");
newSubIteration.setId("185");
iterationCopy.addChild(newSubIteration);
newSubIteration.setParent(iterationCopy);
newSubIteration.setDevelopmentLine(workingDevLine);
service.save(new IProcessItem[] { newSubIteration, iterationCopy, workingDevLine }, monitor);
return newSubIteration;
You should be able to do that through our Java client library. Once you have a com.ibm.team.process.common.IProjectArea you can use methods getDevelopmentLines(), addDevelopmentLine() and setDevelopmentLines() to manage the timelines. Iterations are children of timelines and there are methods in com.ibm.team.process.common.IDevelopmentLine to manage the iterations.
edit: Please note that our Java client library is available as-is and will change over time. It is not a supported API.
edit: Please note that our Java client library is available as-is and will change over time. It is not a supported API.
Comments
Here is the error that I'm getting
Exception in thread "main" com.ibm.team.repository.common.internal.ImmutablePropertyException
at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2060)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:280)
at com.ibm.team.process.internal.common.impl.DevelopmentLineImpl.setName(DevelopmentLineImpl.java:364)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
at $Proxy14.setName(Unknown Source)
at com.progress.iterationCreation.createIteration(iterationCreation.java:73)
at com.progress.iterationCreation.main(iterationCreation.java:31)
Exception in thread "main" com.ibm.team.repository.common.internal.ImmutablePropertyException
at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2060)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:280)
at com.ibm.team.process.internal.common.impl.DevelopmentLineImpl.setName(DevelopmentLineImpl.java:364)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
at $Proxy14.setName(Unknown Source)
at com.progress.iterationCreation.createIteration(iterationCreation.java:73)
at com.progress.iterationCreation.main(iterationCreation.java:31)
String str = "myiteration"
for (Iterator e = developmentLines.iterator(); e.hasNext();)
{
IDevelopmentLine line = (IDevelopmentLine) e.next();
IIterationHandle[] iterationHandle = line.getIterations() ;
for (IIterationHandle iteration : line.getIterations()) {
IIteration iter = (IIteration) repo.itemManager().fetchCompleteItem(iteration, 0, monitor);
System.out.println("Iteration: " + iter.getName());
if (iter.getName().trim().equals(str)) {
System.out.println("Iteration " + str + " already exists ............." );
}else {
iter.getWorkingCopy();
line.setName(str);
line.addIteration((IIterationHandle) iter.getItemHandle());
break;
}
}
}
for (Iterator e = developmentLines.iterator(); e.hasNext();)
{
IDevelopmentLine line = (IDevelopmentLine) e.next();
IIterationHandle[] iterationHandle = line.getIterations() ;
for (IIterationHandle iteration : line.getIterations()) {
IIteration iter = (IIteration) repo.itemManager().fetchCompleteItem(iteration, 0, monitor);
System.out.println("Iteration: " + iter.getName());
if (iter.getName().trim().equals(str)) {
System.out.println("Iteration " + str + " already exists ............." );
}else {
iter.getWorkingCopy();
line.setName(str);
line.addIteration((IIterationHandle) iter.getItemHandle());
break;
}
}
}
I'm trying to create a child iteration, here is my code
newIteration.setId(str);
newIteration.setName(str);
newIteration.setParent(iter);
workingDevLine.setName(iter.getName());
workingDevLine.addIteration((IIterationHandle) newIteration.getItemHandle());
newIteration.setDevelopmentLine(workingDevLine);
service.save(new IProcessItem[]{workingDevLine, newIteration}, monitor);
but here is the error that I'm getting
Unable to login: Timeline 'Parent Backlog' contains iteration 'child iteration' which has a non-null parent iteration. Any idea ?
newIteration.setId(str);
newIteration.setName(str);
newIteration.setParent(iter);
workingDevLine.setName(iter.getName());
workingDevLine.addIteration((IIterationHandle) newIteration.getItemHandle());
newIteration.setDevelopmentLine(workingDevLine);
service.save(new IProcessItem[]{workingDevLine, newIteration}, monitor);
but here is the error that I'm getting
Unable to login: Timeline 'Parent Backlog' contains iteration 'child iteration' which has a non-null parent iteration. Any idea ?
Comments
Hello Rachid,
What you are trying to do is to create a child iteration of an already existing iteration. The method I suggested was for creating Iteration directly under a timeline. It is something like this.
---> Development Line
---> Iteration 1
--->Child Iteration 1.1
--->Child Iteration 1.2
---> Iteration 2
--->Child Iteration 2.1
--->Child Iteration 2.2
The method I suggested will create iteration 1 or iteration 2. But you cannot create any of the child iteration. I will post another code in a few minutes for creating child iteration.
This is my program to create sub-iterations:
public static void createNewIterations(IDevelopmentLine line, Date lastIterationDate)
throws TeamRepositoryException, IOException {
IDevelopmentLine devLineCopy = ((IDevelopmentLine)line.getWorkingCopy());
IIteration newYearIteration = (IIteration) IIteration.ITEM_TYPE.createItem();
newYearIteration.setName(color + " (" + startEnd + ") " + year);
newYearIteration.setId(color + " (" + startEnd + "e33ee20e3ifd " + year);
newYearIteration.setHasDeliverable(true);
newYearIteration.setDevelopmentLine(devLineCopy);
devLineCopy.addIteration(newYearIteration);
IProcessItem[] items = service.save(new IProcessItem[]{devLineCopy, newYearIteration}, null);
IDevelopmentLine devLine2 = (IDevelopmentLine)teamRepository.itemManager().fetchCompleteItem(items[0].getItemHandle(), IItemManager.DEFAULT, null);
IIteration trueNewYearIteration = (IIteration)teamRepository.itemManager().fetchCompleteItem(items[1].getItemHandle(), IItemManager.DEFAULT, null);
IDevelopmentLine devLineCopy2 = ((IDevelopmentLine)devLine2.getWorkingCopy());
IIteration newYearIterationCopy = (IIteration) trueNewYearIteration.getWorkingCopy();
Date newWeekIterationStartDate = dateHelper.addDays(lastIterationDate,1);
Date newWeekIterationEndDate = dateHelper.addDays(lastIterationDate,14);
//Red 2014 I26 (12.22)
int iterationNumber = 1;
while(dateHelper.getYear(newWeekIterationStartDate) != Integer.parseInt(year) + 1){
String weekIterationName = "";
String monthAndDay = (newWeekIterationStartDate.getMonth() + 1) + "." + newWeekIterationStartDate.getDate();
if(iterationNumber <= 9)
weekIterationName = color + " " + year + " IIdei0" + iterationNumber + " (" + monthAndDay + ")";
else
weekIterationName = color + " " + year + " IIdei0" + iterationNumber + " (" + monthAndDay + ")";
IIteration newWeekIteration = (IIteration) IIteration.ITEM_TYPE.createItem();
newWeekIteration.setName(weekIterationName);
newWeekIteration.setId(weekIterationName);
newWeekIteration.setStartDate(newWeekIterationStartDate);
newWeekIteration.setEndDate(newWeekIterationEndDate);
newWeekIteration.setHasDeliverable(true);
newYearIterationCopy.addChild(newWeekIteration);
newWeekIteration.setParent(newYearIterationCopy);
newWeekIteration.setDevelopmentLine(devLineCopy2);
newWeekIterationStartDate = dateHelper.addDays(newWeekIterationEndDate, 1);
newWeekIterationEndDate = dateHelper.addDays(newWeekIterationStartDate, 13);
iterationNumber++;
System.out.println(weekIterationName);
IProcessItem[] iitems = service.save(new IProcessItem[]{devLineCopy2,newYearIterationCopy,newWeekIteration}, null);
devLineCopy2 = (IDevelopmentLine)teamRepository.itemManager().fetchCompleteItem
(iitems[0].getItemHandle(), IItemManager.DEFAULT, null).getWorkingCopy();
newYearIterationCopy = (IIteration)teamRepository.itemManager().fetchCompleteItem
(iitems[1].getItemHandle(), IItemManager.DEFAULT, null).getWorkingCopy();
}
}